Thursday, February 22, 2018

Research Note #9 - Useful Linux Commands for Works

Note: This list could be updated anytime.
Latest update: Feb 22, 2018

1. Show, set and unset the environment variables

$ env (bash)
$ setenv (tcsh, csh)

$ export test=something (bash)
$ setenv test something (tcsh, csh)

$ unset test (bash)
$ unsetenv test (tcsh, csh)

2. Module operation for environment variables

$ module avail (show all available module)
$ module list (show loaded module)

$ module load moduleA (load moduleA into environment variables)
$ module purge moduleA (purge/unload moduleA from environment variables)

3. Run configuration script (bash)

$ . ~/.bashrc

4. Show the type of current active shell

$ echo $0

5. System information (cpu, machine, architecture, distribution)

$ lscpu (shows cpu/socket, cores, threads \ total cpu = sockets x cores x threads)
$ uname -r (shows kernel version)
$ uname -m or uname -arch (shows whether linux is 32-bit or 64-bit)
$ lsb_release -a (shows distribution release name)

6. Renaming wrfout files from UPP with 1 or 2 digits f hour into 3 digits f hour (bash)

$ for f in WRFPRS_d01.[0-9]*; do mv $f `printf WRFPRS_d01.%03d $((10#${f#WRFPRS_d01.}))`; done

7. Counting number of files in a directory from ls command 

$ ls -1 | wc -l

8. Checking memory use

$ top
$ free -mts 10 (shows the current total memory in megabytes, updated every 10 seconds)

9. Suspending a running program, then run it in background or foreground

$ jobs  (showing all jobs, indicated with number in square brackets)
$ bg %1(run job 1 in background)
$ fg %1 (run job 1 in foreground)
$ ./wrf.exe & (run wrf.exe in background)

10. Screen for multisession ssh-connection
$ screen (Open new screen session)
$ ctrl-a (Shows control command)
$ ctrl-a c (Open new screen window)
$ ctrl-a d (Detach screen window)
$ ctrl-a n (Move to next screen window)
$ ctrl-a p (Move to previous screen window)
$ exit (Exit current screen session)
$ screen -r (Retrieve any running screen session)

11. Making GIF animation with ImageMagick
$ convert -delay 25 -loop 0 *.png contoh.gif (makes a contoh.gif from all png file in current directory with infinite loop and 0.25s delay/frame)

No comments:

Post a Comment