You are on page 1of 12

Basic Linux Commands

Sumedh Kakde
What is Linux
Linux is a Unix system
Free
Open Source
Developed by Linus Torvalds in 1991
There are several Linux distributions:
Red hat
Fedora
Ubantu
What is Linux Shell?
Accepts your instruction or command
If it is valid command, it is passed to the
kernel (part of the OS).
Several shells available with Linux.
BASH
To find current shell type:
$ echo $SHELL
To know about command:
Ex: man ls
Files and rights
List your file
$ ls
$ ls l
$ ls a
Display entire file
$ cat filename
Copy
$ cp filename1 filename2
Move or change name
$ mv filename1 filename2
Files and rights
Remove file
$ rm file_name
$ rm -i
$ rm r
$ rm -rf
Display entire file
$ cat file_name
Copy
$ cp file_name1 file_name2
Change permissions
$ chmod [options] file_name
Files and rights
To change the rights, 2 methods with chmod:
$ chmod o+r myfile, chmod g-rw myfile, chmod u=rw,go=r
myfile
$ chmod 777 myfile, chmod 555 myfile
Note: to change the rights on an entire directory:
$ chmod R 777 mydirectory, chmod -R g+rw.

To change the owner: chown
$ chown sumedh myfile


Directories and paths
Make a new directory:
$ mkdir dir_name
. is your current directory
.. is your upper level directory

To Paths can be absolute or relative:
/home/sumedh/bill/foo.txt is an absolute path.
../bill/foo.txt is a relative path.


Directories and paths
Change directory:
$ cd dir_name
$ cd ..
$ cd or cd ~
$ cd ~/bill = cd /home/sumedh/bill
Current directory
$ pwd
Disk usage
$ du file_name
$ du -h


Job Control
List your prcesses:
$ top
$ ps ef
$ ps ef | grep jboss
$ cd ~/bill = cd /home/sumedh/bill
Kill a process
$ kill [options] PID
Ex: $ kill -9 624535
Launch a job in background
$ ./run.sh &



Miscellaneous
Which user you have logged in:
$ whoami
Change the user:
$ su Sumdh_Kakde
Date
$ date
Achieving : tar
$ tar cvzf archieve_name.tar dir_name/
$ tar xzvf archieve_name.tar or archieve_name.tar.gz
File Compression:
$ unzip test.zip



Miscellaneous
Edit files:
$ vi file_name.txt
$ vim file_name.txt
tail command:
Print last 10 lines of the file by default
$ tail file_name.txt
Print last L number of lines from a file
$ tail n L file_name.txt
View the contents of file in real time.
$ tail f log_file.log

You might also like