Wednesday, February 25, 2015

Linux command

PART 1 SIMPLE COMMAND

(1) list directory contents (refer to window dir)
command: ls
Description /purpose: Print or list the file or folder in this directory

[root@server ~]# ls

command: ll
Description /purpose:  Print or list the file or folder in this directory, but this will show information.
[root@server ~]# ll













(2) print name of current/working directory (pwd)
Description /purpose: show which directory or path you are in right now.
[root@server ~]# pwd
/root

(3) copy (cp)
Description /purpose: copy file or create backup

#cp dhcp.conf dhcp.conf.bk

(4)move or rename file ( mv)
Description /purpose:  rename a file name, or generate a file
#mv old.txt new.txt

(5) cat
Description /purpose: read a file name
cat 123.txt

(6)modify text (vi or vim)
Description /purpose: to modify some file
vi is modify, and vim is improve, which will have show in different color.
Some variable need to used

vi











vim

:q! ==>exit without saving
:w! ==>save
:wq!==>save and quit
:x!==>save and exit
? or / ==>search

Note: For more information, please refer shell script



(7) touch
Description /purpose:to generate a file. Different between vi is it don't have to save to generate a file. It will generate a file if input touch command.
touch aaa.txt

(8)tail
Description /purpose: output the last part of files
will print last 10 line 
#tail /var/log/message

 output appended data as the file grows. 
#tail -f

difference from cat versus tail
tail is different from cat, is cat will read all the file once, but tail will not. For example if you have a log file, you cat log file, it will read all the line from first line to last line. But tail will read last line, and if the file still have message, it will also show.

 (9) clear
Description /purpose:clear the terminal screen
#clear


PART 2 Intermediate (common used and file related)

1. extract file
tar -zxvf extract.tar.gz
#tar -zxvf filename.tar.gz 

2. compress file
tar -tzvf compressed.tar.gz
tar -zcvf filnename.tar.gz 'folder destination/'
#tar -zcvf filnename.tar.gz folder /test

3. mount
what is mount?
A mount is where I wants to mount a directory into one folder. Mount this command can used for many ways.
Basely mount this command is like if i have a directory names test, if i wants to mount a directory "dhcp" into test this directory. Directory test all the data will be used by dhcp this directory. In other word mean all test directory will be gone, will only appear dhcp data. If you umount it, it will be appear.

Mount this command can be used for:

Mount for folder to folder which is like shortcut
# mount --bind /etc/dhcp /dhcpfile_test











Mount for usb drive to /mnt directory 




Mount for network 



4 link or shortcut
command "ln -s"
ln -s orginally folder or file shortcut
# ln -s /etc/dhcp/ /dhcpfile











5 set date
date MMddhhmmyyyy




No comments:

Post a Comment