linux/Unix系统管理command杂记

cat:

1. to read content of a file: cat /etc/filename

2. because cat will send file content to screen, so it can be used to copy file. cat /etc/filepath > newfilepath

3. concatenate multiple files into the output: cat file1 file2 file3 > tmpfile4

4. to number non-blank lines in output, use -b option, to number all lines, use -n: cat -b file1; cat -n file1 

5. to squeeze adjacent blank lines, use -s: cat -s file1

 

find:

1. find /path -follow -name filename //-follow makes it to look for symbolic linked file as well

 

screen: a nice article on the setting and operation with screen: http://www.kinnetica.com/2011/05/29/using-screen-on-mac-os-x/ 

basically if you want to customize your screen, you should edit you .screenrc file in your user path. create it if it doesn't exist.  

 

chown:

1. to change the owner/group of a file, use chown owndername:groupname filename: chown liangs:Amazon file

2. to recursively change subfolders and files, use -R option. 

 

mount: to attach device content to system's tree structure

1. to mount a CD device content to linux's root structure: mount dev/cdrom /Shawn/somewhere 

2. it's easy to unmount: umount /Shawn/somewhere 

 

tar: to bundle a bunch of files together and create one archived file

1. tar all files using reg: tar -cvf newFile.tar *.doc

2. tar all files under a director: tar -cvf newFile.tar panda/

3. automatically compress the tar file: tar -zcvf newFile.tar.gz *.doc

4. to list all files in a tar file: tar -tvf alldoc.tar

5. to extract files in a tar file: tar -xvf alldoc.tar  

 

gzip: compress a file with some algorithm.

1. compress a file and replace the old one: gzip filename

2. if you want to keep the original file, then use -c to output and then redirect to a file: gzip -c filename > filename.gz

3. use -r to recursively compress all files under a folder: gzip -r doc/

4. gunzip is the counter part of gzip. So use the same pattern to unzip a compressed .gz file with gunzip 

 

ps: list all running processes in your system

1. ps -ef: list all running processes with full information. use -e to list all entire list, -f to print full format listing

2. ps -f -u userId1, userId2: list processes belong to specific user ids.

3. ps -f -p pid1, pid2: list processes by pid

 

top: show processes information

1. top -u user: list all processes belong to specific users.

 

lsof:

1. lsof without any option: list open flies

2. lsof -i : list all open connection 

3. lsof -i TCP:8080 : list all TCP connection at port 8080; lsof -i :port number can actually show processes on a specific port

4. lsof -c mysql: list all files opened by command, in this example, it lists all files opened by mysql

5. lsof -u username: list files opened by user name

 

netstat: a great article on this command http://www.thegeekstuff.com/2010/03/netstat-command-examples/

1. netstat -a : list all ports 

 

posted on 2012-08-05 06:36  梁霄  阅读(226)  评论(0)    收藏  举报

导航