Monday 24 March 2014

Linux command tips - updating

how to view the process priority

ps -lef  --- l means long mode
you can view the priority and nice value

S   UID   PID  PPID  C PRI  NI   RSS    SZ WCHAN  TTY          TIME CMD
S     0     1     0  0  80   0  1540  4839 poll_s ?        00:00:01 init
S     0     2     0  0  80   0     0     0 kthrea ?        00:00:00 kthreadd
S     0     3     2  0 -40   -     0     0 migrat ?        00:00:00 migration/0
S     0     4     2  0  80   0     0     0 ksofti ?        00:00:00 ksoftirqd/0

how to list only just the first level of directories in a directory

1. find . -maxdepth -type d  (it will include the directory itself)
2. ls -ld */

how to use BASH to read a file line by line

[root@X001 tmp]# while read line
> do
> echo $line
> done < test.txt
this is a test file from rafa
the file is very good ha ha
could you give me the file here
[root@X001 tmp]# cat test.txt
this is a test file from rafa
the file is very good ha ha
could you give me the file here


linux hash command:

Linux uses hash table to speed up the commands finding process. when linux found a command, it stores it in the hash table so next time when it needs to check the command, it can get from hash table. the cost of looking via hash table is O(1)

linux command line {} expand:

when we use { } in bash, it will be expanded by bash.
for example: 
mkdir -pv /var/tmp/{a/b,c} = mkdir -pv /var/tmp/a/b /var/tmp/c

How to recover a file deleted by mistake when it is still opened in the process:

Find the file by ls -l /proc/<pid>/fd/, then copy it by cp /proc/<pid>/fd/<fd> ~/myfile.txt 

No comments:

Post a Comment