Learn Basic and Advanced Unix/Linux/SCM

Advanced Unix/Linux 



File/Directory operations

chmod

=> The command to change permissions on a file or directory.
 -----
chmod 755 test.txt 
 -----
most common permissions are read(4) write(2) and execute(1) Three digits stand for owner(7 rwx), group(5 rx) and other(5 rx).
 -----

 chown & chgrp

=> chown is command to change ownership of a file to a new owner.
=> chgrp is command to change group ownership of a file
 -----
 chown username test.txt
 chown testers test.txt
-----

basename & dirname

=> basename is command to find filename out of filename with full path.
=> dirname is command to find directory out of filename with full path.
-----\
basename /tmp/test.txt o/p test.txt dirname /tmp/test.txt o/p /tmp
-----

ln

=> The command to create link to a file. Links are of two types soft link and hard link. The difference between hard link and soft link is that after deletion soft link will not work but hard link will work.
 -----
ln hardlink test.txt ln -s softlink test.txt
-----

find

=> The command to find files and directories based on given inputs like file name pattern, filetype etc. Its a very powerful command which can be used in combination with grep,exec etc. For more details see man pages on the unix.
-----
Command to find out test.txt in current directory(.)
 find . -name test.txt
-----

grep

=> The command to search for a pattern in a file. There are some advanced grep commands as well like egrep, fgrep etc.
-----
 grep foo test.txt
-----

Output Formatting Commands

awk

=> To be honest it would be wrong to call awk just a command. I consider it as a filtering and formatting language. There are some advanced awk versions as well like nawk, gawk, etc.

 -----
 to list the filesize
ls -lrt | awk 'print "filesize" $8'
-----

sed

=> SED is short form of Stream EDitor. It is very useful in substitution, replacement of data. There are options for global replacement, substitution for specific occurences etc.
-----
  to substitute abc with def sed s/abc/def/ < old.txt > new.txt
-----


Process Management

ps

=> ps is short form of Process Status. It can be used to list out the processes running on the unix server. It has various options like -e -f etc. to sort the output.

 -----
PID TTY TIME CMD 1232 pts/0 00:00:00 bash 3343 pts/0 00:00:00 test.sh 4353 pts/1 00:00:00 ps -----

ptree

kill
=> kill is the command to kill the process forcefully. This is used when you need to get rid of a process which is not needed to continue.
--------
% ps
PID TT S TIME COMMAND
10023 pts/2 S 0:32 sleep 120
21232 pts/2 T 0:21 synergy

To kill the process sleep 120,
% kill 120
---------

pkill

=> pkill is the command to kill the process as well but we dont need to find the PID to kill the process. pkill just need full or partial name of the process which is running.
--------
% ps
PID TT S TIME COMMAND
10023 pts/2 S 0:32 sleep 120
21232 pts/2 T 0:21 synergy

To kill the process sleep 120,
% pkill sleep 120
---------
     

No comments:

Post a Comment