Linux Commands

General Info

You can look at the prompt symbol to find out the type of user logged in.
Generally it will be $ for the ordinary users and # for root user.
$ symbol is used in most of the shells (like bash etc.,) and % sign is used in C Shell.

FAQ- How to's..

  • What is /proc/core ?

Have a look at here -> http://www.unixguide.net/linux/faq/04.16.shtml [Info from the url: /proc/kcore is like an "alias" for the memory in your computer. Its size is the same as the amount of RAM you have]

  • dfd

Special Characters as commands

  • Tilde symbol (~)
    • Used as a short hand for the user's home directory.
    • Usage : cd ~ takes you to the user's home directory from wherever you were and executed this command
  • bang,bang (!!)
    • From the C shell, these characters are used to repeat the previous command execution.
    • It will reexecute the previously executed command in the shell.
      • As the "!" (exclamation mark) is called a bang, this is called as "bang,bang".
      • Example:
        1. user1 $ df -k (disk free with kilobytes option)
        2. user1 $ !! ==> runs the same command "ls -la" here as well.
    • With bash,tcsh, or csh, !! will display the previous command (df -k in this exampe) and then execute that command.
  • Exclamation, Dollar (!$)
    • Used to make use of the argument in the previous command.
    • Supported in bash, csh but NOT in korn shell.
    • It takes the last argument of the previous command and makes use in the present command.
      • You can make use in combination with a number like "!<Number>" wherein the Number represents the entry corresponding to the command stored in history. If you say, "!5", it will execute the 5th command stored in history.
    • Example:
      1. user1 $ file index.html (to identify the file type using file command)
      2. index.html: HTML document text (Output of the 'file' command)
      3. user1 $ cat !$ | more ("cat" displays the file content, whose output is redirected using the pipe (|) symbol to "more" command which facilitates one screen at a time while pressing the spacebar advances to the nextscreen whereas the 'esc' key quits the display)
    • You can use partial characters along with the ! key as, "!<Charcter(s)>", whereas the recently executed command in the history matching the character entered is executed again.
      • Example:
        1. If you use "!l", it will try to execute the command in the history, which starts with the character "l".
        2. If there are more than one commands start with "l", the recent one from the bottom will get executed.
      • dfa
    • dfd
    • adsfa
  • asdfas

C

  • cpio

cpio for copy the files from streams and in and out of archive files (say .tar files). There are 3 modes to operate. Look at the manual for the detailed description.

  • crontab

used to deal the cronjobs running/present in the machine for the user logged in. You have to specify an argument to get the output.

Generally, crontab -l lists. and crontab -e allows you to edit the cronjob being listed. crontab -r is to delete the crontab.

Sample output of crontab -l goes as follows

*/30 * * * * /bin/sh /home/loguser/lmrwas-p/script/logbkp_new.sh » /home/loguser/lmrwas-p/script/logbkp_new.cron 2>&1

30 -> for 30 minutes (every 30 mts it will run)
/bin/sh —> for the shell to invoke
/home/loguser/lmrwas-p/script/logbkp_new.sh —> shell script to invoke at the scheduled time
/home/loguser/lmrawas-p/script/logbkp_new.cron —> file to append the output of invoking logbkp_new.sh file
2>&1 —> when an error occurs and the script does not get executed properly, redriect the output from Standard Error (2) to Standard Output (1). for redirection, you can see http://www.linuxsa.org.au/tips/io-redirection.html

  • afdas

D

  • dd

dd stands for data dumper. It is for taking backups. See the manual for detailed information.

  • du - Disk Usage
    • http://linuxreviews.org/man/du/ -> explains neatly.
    • However, some other shortcuts which I have accumulated from various websites:
      • du -h —max-depth=1 <partition_to_search> —> you can give "/", "/tmp", "/var" etc., based on the needs when it comes to clean up your disk once it gets filled.
      • du -sh ./* | sort -rn — to give all the files and their sizes. You can avoid 'h' if you don't need the human readable (K, M etc.,) for the sizes. It would be useful when you give this output to 'sort' command. -r is for reverse, -n is for numeric values.
  • adfasa

E

  • env

or list a specific variable with the echo command, prefixing the variable name with a dollar sign (the second line shows the result of the echo command):

  • echo $HOME

/home/hermie

You've already learned how to customize your shell prompt with the PS1 variable. The HOME variable is one you shouldn't mess with, because lots of programs count on it to create or find files in your personal home directory.

  • echo $SHELL

prints out the shell being used. Generally, bin/bash for the bash (bourne again shell) and its default location which is subjective to change according to the type of the flavour (unix flavour)

  • echo $?

displays the status of the previously run command. Genearlly 0 for success and any non zero value for failure.

  • adfas

F

  • file

The file command is used to display the file type whether it is a plain text file or binary file or shell script etc.,

Usage: file <fileName>
Example:
user1 $ file index.html
index.html : HTML document text

  • find

Find command is used to find for a file in the filesystem.

It is usage is described here :

http://www.cyberciti.biz/tips/linux-findinglocating-files-with-find-command-part-1.html
http://www.cyberciti.biz/tips/linux-findinglocating-files-with-find-command-part-2.html

  • afdasas

G

grep
grep -q —> to suppress the output to be printed on the console. it works "q"ueitly.

H

history
With no options and by default displays the set of commands you have entered with the line numbers for each command. You have an option to clear the history by issuing an option "-c" which clears the history by deleting all entries.

More in it is available in "man history" :)

L

  • ls

Most infamous command equivalent to dir in MS-DOS. ls stands for listing! can have many options
ls -l —> long listing
ls -la —> list all files
ls -lrt —> long listing in a reverse order (r) with the time of modification (m).

  • afdsa

P

PS1 defines the shell's command-line prompt.

· HOME defines the home directory for a user.

· PATH defines a list of directories to search through when looking for a command to execute.

To list the current values of all environment variables, issue the command

S

U

  • Uname

This 'uname' command, originally short for unix name, displays the information of the operating system where it is running. It is like the host name, operating system, kernel version, kernel revision etc.,

Many options are given as : -a (for all), -p (for processor), -o (for OS), -s (for kernel name) etc.,
Default is like with -s (if you give without any options)

  • uniq

This command prints the unique lines which is read/fed from the Input stream (by default from the standard input stream) and prints the unique lines (discards all but one of successive identical lines) to the output stream (by default to the standard output stream).

NOTE: Have a careful look at the term 'successive' in the definition above. It just discards the duplicate line out of adjacent lines and NOT on the whole content read from the input stream! If you do so, you have to use "sort" to get the contents sorted first and then get the "uniq" command done as expected!! [ // taken from 'info uniq' command manual //]

Alternative: You can get the unique lines in the input stream contents by using, "sort -u" command itself.

Usages:

"cat uniqDemo.txt | uniq" --> lists the unique lines out of adjacent lines
"cat uniqDemo.txt | sort | uniq" --> lists the unique lines in the entire uniqDemo.txt file (as they are sorted first)
"cat uniqDemo.txt | sort -u" --> same as above!
  • dfd

W

  • wget

A non-interactive network downloader http://linux.die.net/man/1/wget

  • dfd
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.