Sunday, March 6, 2011

some linux command tips

1.

To ignore upper/lower case distinctions, use the -i option, i.e. type
% grep -i science science.txt 
2.  wc command, short for word count.
3.
Some of the other options of grep are:
-v display those lines that do NOT match
-n precede each matching line with the line number
-c print only the total count of matched lines

4. The character ? will match exactly one character.

5.whatis
gives a one-line description of the command, but omits any information about options etc.

6. To background a process, type an & at the end of the command line. For example, the command sleep waits a given number of seconds before continuing
sleep 10
sleep 10 &

7. jobs
8. fg  To restart (foreground) a suspended processes, type
% fg %jobnumber
9. quota
To check your current quota and how much of it you have used, type
% quota -v
10. du
The du command outputs the number of kilobyes used by each subdirectory
du -s *

11. zcat
zcat
will read gzipped files without needing to uncompress them first.
12. file
file classifies the named files according to the type of data they contain, for example ascii (text), pictures, compressed data, etc.. To report on all files in your home directory, type
file *
13. find
This searches through the directories for files and directories with a given name, date, size, or any other attribute you care to specify.
To search for all fies with the extention .txt, starting at the current directory (.) and working through all sub-directories, then printing the name of the file to the screen, type
find . -name "*.txt" -print
To find files over 1Mb in size, and display the result as a long listing, type
% find . -size +1M -ls
14. history
The C shell keeps an ordered list of all the commands that you have entered
% history (show command history list)
If you are using the C shell, you can use the exclamation character (!) to recall commands easily.
% !! (recall last command)
% !-3 (recall third most recent command)
% !5 (recall 5th command in list)
% !grep (recall last command starting with grep)
15.
You can increase the size of the history buffer by typing
% set history=100

No comments:

Post a Comment