Basic LINUX commands (for Putty)

@mit $ingh. February 13, 2015 Comments

Navigating directories

>>> cd(change directory) command used for moving from one folder to another.

cd  foldername/foldername2
>>> Take you to foldername2.

cd ~
>>> Take you to the home directory.

cd -
>>> Take you to the last directory where you are in.

cd ..
>>> Moves up one directory.

cd /
>>> Moves you to root.

>>> Use this command to find out where are you currently in.


List contents

>>> List contents of current directory.

ls -l
>>> Lists long format inc. group owner, size, date modified, permissions.

ls -a
>>> Lists ALL files including hidden files.

ls -al
>>> Lists ALL files with information.

ls -alh
>>> Lists all files and folders with detailed information including file size.

ls *.ext
>>> Lists all files ending with certain extension.

ls -R
>>> Lists contents of sub directories recursively.

ls -la
>>> The above options can be used at the same time.

ls foldername/foldername
>>> Lists items in folder without actually moving to it.


File Management

touch file.html
>>> Use the touch command to create files.

rm file.html
>>> Remove a file.

rm *
>>> Remove all files in the current directory.

rm *.extension
>>> Remove all files with certain extension.

rm -rf !(file.txt)
>>> Remove all files and folders except file.txt.

mkdir myfolder
>>> Create a new directory/folder.

rmdir myfolder
>>> Remove a directory/folder, folder must be empty.

cp banner.jpg ads/banner728px.jpg
>>> Copy and renaming at once.

cp -r [directory] [new directory]
>>> Copy a folder with all files and folders in it.

mv banner.jpg ads/banner728px.jpg
>>> Moving a file to another directory and renaming it at once.

mv image/ ..
>>> Moving “image” folder to upper directory.

find . -name banner.jpg -print
>>> Find a file called “banner.jpg” in current folder.

grep sidebar index.php
>>> Find the word “sidebar” in file index.php

chmod 777 config.php
>>> Change file and folder permission.

chmod -r 755 myfolder
>>> Changes permissions for that folder and all folders and files inside it recursively.

Available permission type: (below are not commands)
First number is for the owner, second for the group, and third for everyone.
7 = Read + Write + Execute
6 = Read + Write
5 = Read + Execute
4 = Read
3 = Write + Execute
2 = Write
1 = Execute
0 = All access denied


Compressing and backing up files and folders

zip -r foo/
>>> Compress the folder ‘foo’ and all of its contents into a zip file called ‘’.

zip foo.html
>>> Compress the file’foo.html’ into a zip file called ‘’.

unzip -p /path/example.php > /path/example.php.
>>> unzip only one file from zif file(example.php)


MySql Databse export and import command

Export command

mysqldump -u root -p database_name > file_name.sql

Import command

mysql -u root -p database_name < file_name.sql


Set linux environment PATH variable

Add in the last
export PATH=$PATH:/path/to/dir1

Add in the beginning
export PATH=/path/to/dir1:$PATH


You just execute the below command to reset the PATH variable for the current session.
If you want to change permanently add it to any .bashrc, bash.bashrc, /etc/profile - whatever fits your system and user needs.

export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games


Edit any files in putty.

vi filename

i to insert
a to append
x to delete
dd to delete a line

    : to begin a command sequence
    :w to write
    :q to quit
    :q! to quit without saving
    :wq to write and quit


Options :-

-a  Shows you all files, even files that are hidden (these files begin with a dot.)

-A  List all files including the hidden files. However, does not display the working directory (.) or the parent directory (..).

-b  Force printing of non-printable characters to be in octal \ddd notation.

-c  Use time of last modification of the i-node (file created, mode changed, and so forth) for sorting (-t) or printing (-l or -n).

-C  Multi-column output with entries sorted down the columns. Generally this is the default option.

-d  If an argument is a directory it only lists its name not its contents.

-f  Force each argument to be interpreted as a directory and list the name found in each slot. This option turns off -l, -t, -s, and -r, and turns on -a; the order is the order in which entries appear in the directory.

-F  Mark directories with a trailing slash (/), doors with a trailing greater-than sign (>), executable files with a trailing asterisk (*), FIFOs with a trailing vertical bar (|), symbolic links with a trailing at-sign (@), and AF_Unix address family sockets with a trailing equals sign (=).

-g  Same as -l except the owner is not printed.

-i  For each file, print the i-node number in the first column of the report.

-l  Shows you huge amounts of information (permissions, owners, size, and when last modified.)

-L  If an argument is a symbolic link, list the file or directory the link references rather than the link itself.

-m  Stream output format; files are listed across the page, separated by commas.

-n  The same as -l, except that the owners UID and groups GID numbers are printed, rather than the associated character strings.

-o  The same as -l, except that the group is not printed.

-p  Displays a slash ( / ) in front of all directories.

-q  Force printing of non-printable characters in file names as the character question mark (?).

-r  Reverses the order of how the files are displayed.

-R  Includes the contents of subdirectories.

-s  Give size in blocks, including indirect blocks, for each entry.

-t  Shows you the files in modification time.

-u  Use time of last access instead of last modification for sorting (with the -t option) or printing (with the -l option).

-x  list entries by lines instead of by columns.

  • linux
  • linux-command