Search

Sunday, January 23, 2011

Common used Linux console commands

Most used Linux' console commands
environment : Fedora 14 minimum installation




ln
Create a link from one file or directory to another file or directory.


ln -s /bin/program prolinkCreate a soft link (shortcut) from the existing file /bin/program to prolink. The link prolink is created in the current working directory. If you enter the command prolink, you run the program /bin/program.


pwd
show the path to the current working directory.


find

Find files under a specified directory that match conditions you specify.

find / -name myfil*Find files in the root directory and all directories under it that have file names beginning with myfil. The * is a wild-card character that represents any number of characters. The ? is a wild-card character that represents a single character.

find -name '*.vmx' -print -exec chown User2 {} \;Find all files in this directory and all subdirectories that end with .vmx, display the names of all files that are found on the screen and, for each file (indicated by the curly braces — {}), change its owner to User2.
 The -print option is not necessary, but it is handy to track the progress of the find command. If you do not use -print, the find command is silent except for error messages from find or from chown.

find -name '*.vmx' -exec grep -il 'SOMETHING' {} \;Find all files in this directory and all subdirectories that end with .vmx and look for the pattern SOMETHING in each of the files. The -i option to grep makes the search case-insensitive. The -l option to grep causes grep to display the names of the files that have SOMETHING in them. When a file is found that contains SOMETHING, this command displays the full path to the file from the current directory (for example,
./virtualmachines/Linux/RedHat71Test/redhat71.vmx
).

grep
Search for a specified text pattern in a specified directory or list of files and display the lines in which the pattern is found.

grep "log file" *Search all the files in the current directory for the text string log file.



sed
It would be nice if we could automate the process of making edits to files, so that we could "batch" edit files, or even write scripts with the ability to perform sophisticated changes to existing files. Fortunately for us, for these types of situations, there is a better way -- and the better way is called "sed".


sed is a lightweight stream editor that's included with nearly all UNIX flavors, including Linux. sed has a lot of nice features. First of all, it's very lightweight, typically many times smaller than your favorite scripting language. Secondly, because sed is astream editor, it can perform edits to data it receives from stdin, such as from a pipeline. So, you don't need to have the data to be edited stored in a file on disk. Because data can just as easily be piped to sed, it's very easy to use sed as part of a long, complex pipeline in a powerful shell script. Try doing that with your favorite editor.

Examples :
$ sed -e 'd' /etc/services
$ sed -e '1d' /etc/services | more
$ sed -e '1,10d' /etc/services | more
$ sed -e '/^#/d' /etc/services | more
$ sed -e '/regexp/d' /path/to/my/test/file | more

Combine with find file command (using regex replacement and keeping part of string) :

$ find -name '*.php' -exec sed -i 's/find_text\(aa\)/replace_text\1/' {} \;

source : http://www.ibm.com/developerworks/linux/library/l-sed1.html

su
login to someuser from super user

$ su - someuser

export
export command- Set an environment variable
Syntax: export [-fn] [-p] [name[=value]]
Description: The export command makes available variables to all child processes of the running script or shell. One important use of the export command is in startup files, to initialize and make accessible environmental variables to subsequent user processes.

mv
move file(s) from source to some directory

$ mv file_name  new/directory/to/move/file/to

rename file / folder
$ mv old_file_name new_filename
$ mv old_dir_name new_dir_name

ps
show every process on system
#ps -A
see every process running except those as root
#ps -U root -u root -N
see every process ran by user user1
#pas -u user1
source : www.cyberciti.biz/faq/show-all-running-processes-in-linux







Further Reading :
http://www.vmts.net/article/linuxcommand.htm

No comments:

Post a Comment