touch, cat, mkdir, cd, pwd, rm, ls, more, less, head, tail, cp, mv, man, info, whatis command:

Linux Terminals (by default 7):

 

CLI: by default 6 terminals (can be increased upto 63)

GUI: by default 1 (can be increased 33/34)

 

Alt + ctrl + F1
(go to 1st CLI Terminal)

 

Alt + ctrl + F5
(go to 5th CLI Terminal)

 

Alt + ctrl + F7
(go to 7th GUI Terminal)

 

# denote super user (Priviledge User)
$ denote normal user (Non-Priviledge User)

 

To Logout: Alt + ctrl + backspace

 

To create an empty file file1
touch file1

To create a file file2:

cat>file2                                            
This is the content of file2
(press ctrl + d to save and exit)

To change Date and Time
date mmddhhmmyyyy

To Create Directory (dir1):
mkdir dir1

To Create Directory
(dir2 in /tmp folder):
mkdir    /tmp/dir2

{-p switch create parent directory (dir3 in this case) if it doesn’t exit}
mkdir  –p   /tmp/dir3/dir4

Example 2:
mkdir -p  /dump/{Server,VT,Cluster,ClusterStorage}

 

To change directory:
cd /dir1
(Change current directory to /dir1)

 

cd  /dir1/dir2
(Change current directory to dir2 which is located in /dir1)

 

cd               
(Change current directory to your HOME directory.)

 

cd /usr/dir2
(Change current directory to /usr/dir2)

 

cd INIT
(Change current directory to INIT which is a sub-directory of the current directory.)

 

cd ..
Change current directory to the parent directory of the current directory.

 

cd ~wali
(Change the current directory to the user wali's home directory (if you have permission)

 

Note:
Directories:
File and directory paths in UNIX use the forward slash "/" to separate directory names in a path.

 

Examples:
/              "root" directory
/usr           directory usr (sub-directory of / "root" directory)
/usr/wtuto wtuto is a subdirectory of /usr

 

To display the "path of working directory", or current directory:
pwd

To delete directory, subdirectories and files (r= recursively, f=forcely)
rm –rf dir1 
(Where dir1 has subfolder and files in it)

 

Listing files and folders:
ls
(display files and folders in current directory)

 

ls –a
(List the current directory including hidden files. Hidden files start with ".")

 

ls -ld *
(List all the file and directory names in the current directory using long format. Without the "d" option, ls would list the contents of any sub-directory of the current. With the "d" option, ls just list them like regular files.)

 

ls –l
(-l switch to display details)

 

for example:
$ ls -l
drwxr-xr-x   4 cliff  user        1024  Jun 18 09:40 dir1
-rw-r--r--     1 cliff  user      767392 Jun  6 14:28  file1
^ ^  ^  ^    ^ ^    ^           ^          ^      ^         ^
| |  |  |         |   |     |            |            |        |        | 
| |  |  |         | owner  group size     date   time  name
| |  |  |        number of links to file or directory contents
| |  |  permissions for world
| |  permissions for members of group
| permissions for owner of file: r = read, w = write, x = execute -=no permission
type of file: - = normal file, d=directory, l = symbolic link, and others...

 

ls li
(-i switch to display inode number of files and folders)

 

ls -R directory
(-R to display recursive list of directory)

 

Note:
An inode contains full information of a file or a folder like name, user owner, group owner, location, time of creation, permission etc.

 

To display content of files:
cat  file1                     
(display contents of file1)

more   file1                
(display contents pagewise only in downward direction (Where Enter = One Line Down, Spacebar = Page Down, q=quit)

less  file2                    
(display contents pagewise in both upward & downward direction)

head file1
(display first few lines of file1

 

head -n /etc/passwd
(display n number of lines from the beginning of file)

 

tail file1
(display last few lines of file1)

tail -n /etc/passwd
(display n number of lines from the end of file)

 

tail -f /var/log/messages
(output appended as the file grows)

 

Note:
Filename Completion

A feature of bash and tcsh (and possibly others) you can use the TAB key to complete a partially typed filename. For example if you have a file called constantine-monks-and-willy-wonka.txt in your  directory and want to edit it you can type 'vi const', hit the TAB key, and the shell will fill in the rest of the name for you (provided the completion is unique).

 

To delete files and folders:
rm  filename
(to delete a file)

rmdir  directory
(to delete an empty directory)

rm  -r  dir1
(recursivly remove a directory and its contents BE CAREFUL!)

rm  -rf  s[1-5]
(to delete s1, s2, s3, s4 & s5)

 

To Copy:

The cp command makes a copy of a file. For example, type:

 

cp  foo bar
(to make an exact copy of foo and name it bar. foo will be unchanged)

 

cp  dir1 /xyz
(to make an exact copy of dir1 in /xyz folder. )

 

To move or rename:

The mv command moves a file to a different location or will rename a file. Examples are as follows:

 

mv  foobar
(will rename the file foo to bar)

 

mv foo ~/Desktop
(will move the file foo to your Desktop directory but will not rename it.)

 

mv dir1 /abc
(to make an exact copy of dir1 in /xyz folder.)

 

Getting help
# whatis  mkdir
whatis  is command provides you a short description about the command that you type after it. Above command provides a short description on mkdir command.

# mkdir   
--help              
-- help switch also provide you a short description about the command and its switches. Above command provides a short description on mkdir.

# man mkdir              
# info  mkdir

man
and info command provide you a manual page (long notes) about the command you type after it.

  • whatis                               
    # whatis  mkdir

  • command --help              
    # mkdir    --help

  • man
    #man  mkdir

  • info
    #info  mkdir


Help file also available in:

  • /user/share/doc/
  • Red Hat documentation


Note:
#makewhatis (to install whatis, first)

You can search through the man pages using apropos

 

Example:
apropos build     Shows a list of all the man pages whose discriptions contain the word "build"

 

Do a man apropos for detailed help on apropos.

.

Connect With Us
Instant Query
Your Name :

Email Address :

Message :