CopyPastehas never been so tasty!

40 Useful Commands For Linux OS

by anonymous

  • 0
  • 0
  • 0

Orignal source:

Denotes the super(root) user


indicate usual user


/root: indicate super user’s directory


/home: Denotes the normal user’s directory.


Switching connecting Terminals


§ Ctrl + Alt + F1-F6: Console login


§ Ctrl + Alt + F7: GUI login

The Magic Tab:
In its place of typing the whole filename if the only one of its kind prototype for a meticulous file is given then the exceptional typescript call for not be type and can be get hold of mechanically using the tab Button.
(Tilde): Denotes the current user’s home directory
Ctrl + Z: To end a command that is working interactively without come to an end it.
Ctrl + C: To discontinue a command that is not responding. (Cancellation).
Ctrl + D: To send the EOF( End of File) signal to a command normally when you see ‘>’.
Ctrl + W: To rub out the text you have come into a word at a time.
Up arrow key: 
To redisplay the last executed command. The Down arrow key can be used to print the next command used after using the Up arrow key previously.
The history command can be vacant using a simple option –c (clear).
cd :   The cd command can be used trickily in the following ways:
cd : To knob to the home user
cd * : To transform directory to the first file in the directory (only if the first file is a directory)
cd .. : To budge back a folder
cd - : To return to the last directory you were in
Files starting with a dot (.) are a hidden file.
To vision concealed files: ls -a
ls: The ls command can be use trickily in the following ways:
ls -lR : To view a long list of all the files (which includes directories) and their subdirectories recursively .
ls *.* : To view a list of all the files with extensions only.
ls -ll: Gives a long list in the following format
drwxr-xr-x 2 root root 4096 2010-04-29 05:17 bin where
drwxr-xr-x : permission where d stands for directory, rwx stands for owner privilege, r-x stands for the group privilege and r-x stands for others permission respectively.
Here r stands for read, w for write and x for executable.
2=> link count
4096=> directory size
2010-04-29=>date of creation
05:17=> time of creation
bin=>directory file(in blue)
The color code of the files is as follows:
Blue: Directory file
White: Normal file
Green: Executable file
Yellow: Device file
Magenta: Picture file
Cyan: link file
Red: Compressed file
File Symbol
-(Hyphen) : Normal file
l=link file
b=Block device file
c=character device file


Using the rm command: 
When used devoid of any choice the rm command deletes the file or directory ( option -rf) without any warning. A easy mistake like rm / somedir instead of rm /somedir can root chief turmoil and delete the complete content of the /(root) directory. 
Hence it is always prudent to use rm command with the -i(which prompts before removal) option. Also there is no undeleting option in Linux.
Copying hidden files: cp .* (copies hidden files only to a new destination)
dpkg -l : To get a list of all the installed packages.
Use of ‘ > ‘ and ‘ >> ‘ : The ‘ > ‘ symbol ( input redirector sign) can be used to affix content to a file when used with the cat command. Whereas ‘ >> ‘ can be used to append to a file. If the ‘ >> ‘ symbol is not used and content is added to a file using only the ‘>’ symbol the previous content of the file is deleted and replaced with the new content.
e.g: $ touch text (creates an empty file)
$ cat >text
This is text’s text. ( Save the changes to the file using Ctrl +D)
Output of the file:
This is text’s text.
This is a new text.
 To count the number of users logged in : who |wc –l
cat:  The cat command can be used to trickly in the following way:
To count no. of lines from a file : cat <filename> |wc -l
o count no. of words from a file : cat <filename> |wc -w
To count no. of characters from a file : cat <filename> |wc –c
To search a term that returns a pattern: cat <filename> |grep [pattern]
The ‘tr’ command: Used to translate the characters of a file.
tr ‘a-z’ ‘A-Z’ <text >text1 : The command for example is used to translate all the characters from lower case to upper case of the ‘text’ file and save the changes to a new file ‘text1′.
File permission using chmod: ‘chmod’ can be used directly to change the file permission of files in a simple way by giving the permission for root, user and others in a numeric form where the numeric value are as follows:
e.g. chmod 754 text will change the ownership of owner to read, write and executable, that of group to read and executable and that of others to read only of the text file.
More: It is a filter for paging through text one screenful at a time.
Use it with any of the commands after the pipe symbol to increase readability.
e.g. ls -ll |more
cron : Daemon to execute scheduled commands. Cron enables users to schedule jobs (commands or shell scripts) to run periodically at certain times or dates.
1 * * * * echo “hi” >/dev/tty1 displays the text “hi” after every 1 minute in tty1
.—————- minute (0 – 59)
| .————- hour (0 – 23)
| | .———- day of month (1 – 31)
| | | .——- month (1 – 12) OR jan,feb,mar,apr …
| | | | .—– day of week (0 – 7) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
* * * * * command to be executed
Source of example: Wikipedia
fsck: Used for file system checking. On a non-journaling file system the fsck command can take a very long time to complete. Using it with the option -c displays a progress bar which doesn’t increase the speed but lets you know how long you still have to wait for the process to complete.
e.g. fsck -C
To find the path of the command: which command
e.g head -n 4 abc.c is used to extract the first 4 lines of the file abc.c
e.g tail -n 4 abc.c is used to extract the last 4 lines of the file abc.c
Any changes to a file might source loss of imperative data unknowingly. Hence    Linux creates a file with the same name followed by ~ (Tilde) sign without the recent changes. This comes in really handy when playing with the configuration files as some sort of a backup is created.
A variable can be defined with an ‘=’ operator. Now a long block of text can be assigned to the variable and brought into use repeatedly by just typing the variable name preceded by a $ sign instead of writing the whole chunk of text again and again.
e.g ldir=/home/my/Desktop/abc
cp abcd $ldir copies the file abcd to /home/my/Desktop/abc.
To find all the files in your home directory modified or created today:
e.g. find ~ -type f -mtime 0
For a continuation of this topic refer to our next stone Basic-command-line-tips-tricks-ii

Add A Comment: