BELOW YOU CAN FIND IMPORTANT UNIX / LINUX COMMANDS THAT ONE SHOULD MEMORIZE IN ORDER TO WORK EFFICIENTLY ON UNIX / LINUX SYSTEMS
*************** How To Create new Users in Linux / Unix ************************
| Add New User in Linux (ubuntu) |
NOTE :: If you are not logged in as a "root" user you should append "sudo" in the "adduser" command like below :
# sudo adduser user-a
*************** How To Switch Users in Linux / Unix *****************************
| Switch users in Linux |
$ whoami
user-a
// whoami command will tell you the name of logged in user
$ su - user-b
Password:
// use command
$ whoami
user-b
$ exit
logout
// exit will logout the user
Note : $ sudo // this means super user do . You can run any command as super user whenever required like this
$ sudo service tomcat7 restart
************************ Directory Navigation ********************************
| Directory Navigation in Linux |
The directory you are standing in is called the working directory. To find the name of the working directory, use the pwd command.
$ pwd
/home/user-b
$ cd
example :
1. $ cd /tmp/user - this command will take you inside
TIP ! ::: Press TAB to display list of available directories in your current directory.
// cd stands for change directory , it will take you to the directory you want by specifying the path of directory with its name.
$ ls
// ls command will list all available directories & files in your working directory, if you want to list files / directories present at a path other than working directory than simply specify the path with directory name to list all available files/directories
example : $ ls /tmp/user-a/
Above command will display all available directories & files at /tmp/user-a/
************************* File & Directory Operations *******************************
Now that we have learned how to create new user , switch to that user, navigate to the desired location in linux file system, we should now learn how to operate on files & directories present on linux system. You can consider this part as the most important in your linux knowledge as this will help you in your everyday working routine of linux
Create a new directory
$ mkdir
| Make Directory in Linux |
Above command will create a new directory with name dir3 at path /tmp/linux-command/ as it is your working directory. You can create directory at any other path by simply specifying the path in your command as shown below
user-b@Ubuntu1204:/tmp/linux-command$ mkdir dir3/dir4
user-b@Ubuntu1204:/tmp/linux-command$ ls dir3/
dir4
user-b@Ubuntu1204:/tmp/linux-command$
This will create directory "dir4" inside directory "dir3"
Create a new file :
$ touch
| Create new file using "touch" command in linux |
Above command will create a new blank file "newfile4" at /tmp/linux-command$
Edit / view file :
$ vi
This will open file in view mode using "vi" editor available in linux
Press "i" to enable insert mode in order to insert / delete some text in file .
Press "Esc" ":wq!" & enter to same your entries & exit. (wq will write & quite the file)
user-b@Ubuntu1204:/tmp/linux-command$ vi newfile4
| Vi editor - Insert |
| Vi editor - save & quite |
$ cat
user-b@Ubuntu1204:/tmp/linux-command$ cat newfile4
| Cat command to view files contents in linux |
cat command will display the contents of your file on your command line
You can also view the contents by restricting them to some number of lines from files head/top or tail/bottom
| Head / Tail to view file in Linux |
user-b@Ubuntu1204:/tmp/linux-command$ head -1 newfile4
This is dummy file for learning linux - Tushar Agrawal
// This way it will display only the first line of the file.
user-b@Ubuntu1204:/tmp/linux-command$ head -3 newfile4
This is dummy file for learning linux - Tushar Agrawal
second line
3rd line
// This way it will display the first 3 lines of the file
user-b@Ubuntu1204:/tmp/linux-command$ tail -1 newfile4
4th line
// This way it will display last one line of the file
user-b@Ubuntu1204:/tmp/linux-command$ tail -2 newfile4
3rd line
4th line
// This way it will display last 2 line of the file
user-b@Ubuntu1204:/tmp/linux-command$
Rename file / Directory
$ mv
user-b@Ubuntu1204:/tmp/linux-command$ mv newfile4 newfile4-renamed
| mv command to rename file |
Above command will rename file "newfile4" to "newfile4-renamed", same way we can rename a directory as shown below
| mv command to rename directory |
Copy file from any location
$ cp
| copy files in Linux |
Above command will copy file "newfile4-renamed" from "/tmp/linux-command/" to "/tmp/linux-command/dir11/"
Zip / UnZIP / tar / untar directory / files
Command to create a tar file
$ tar -cvf
| Create tar file |
Command to extract contents of a tar file
$ tar -xvf
| Extract tar file |
Deleting directory & files
$ rm
| Remove file in Linux |
Above command can not be used to delete directory, to remove a directory use below command which uses recursive force "rf"
$ rm -rf
| Remove directory in Linux |
File Permission
$ chmod 777 // for all permissions (read + write + execute)
Following are the symbolic representation of three different permissions:
r is for read permission,
w is for write permission,
x is for execute permission.
************ Unix Linux Administration ******************
apt-get update // to update linux store
apt -get upgrade // to upgrade linux store
++ More to come+++