
SSH is the short form of Secure Shell or Secure Socket Shell. SSH is an encrypted protocol to connect and communicate between two systems using a secured link over an unsecured network. Tatu Ylonen developed it in 1995. The SSH protocol’s three layers are the authentication, transport, and connection layers.
SSH commands in Linux
SSH command is a command used in Linux. There are many SSH commands in Linux, such as terminal commands, file listing commands, etc. Following are the commonly used SSH commands in Linux.
- ls Command
- cd Command
- pwd Command
- In Command
- mkdir Command
- rm Command
- cat Command
- cp Command
- mv Command
- kill Command
- chmod Command
- wc Command
- rmdir Command
- tail Command
- more Command
- grep Command
- find Command
- pico Command
- vi/nano Command
- history Command
- clear Command
- tar Command
- file Command
- wget Command
- du Command
- du -sh Command
- ps Command
- touch Command
- last Command
- netstat Command
- zip Command
- unzip Command
- reset Command
- exit Command
ls Command
ls Command is a directory and file listing command. It lists the directory content, i.e.; files and directories.
Syntax: ls [Options] [File]
ls command can be customized with several options to differentiate the outcomes. The commonly used options in ls command are the following.
- ls -a
ls -a display all files including hidden file starting with the dot (.).
Example:
O → ls -a
. brave Downloads g01.13.5.linux – amd64.tar.gz Music .python_history
.. bse .eclipse .gphoto .mysql_history .python_history – 21278.tmp
article_images bsedata eclipse .gradle .node – gyp . qd
assignment .bundle eclipse-workspace index.php .npm raycast.txt
.atom .cache .emacs.d info-page-content .nvm sample_assignments
.bash_history cloning en-GB info-page-content.zip .p2 .sass – cache
.bash_it .config flameshot_ss insta Pictures share
.bash_logout .dbshell .gem .local .pkt snap
.bash_profile .degit git .m2 .profile solution-info-content
.bashrc Desktop .gitconfig meetings .profile.save solution-info-content.zip
.bashrc.bak development .gnome .mongorc.js .psql_history solution-page-content
bin Documents . gnupg .mozilla Public solution-page-content.zip
- ls -d */
ls -d */ displays only the sub-directories.
Example:
O → ls -d */
article_images / bin / Desktop / Documents / eclipse / en – GB / info – page – content / meetings / sample_assignments /
assignment / bse / development / Downloads / eclipse-workspace / git / insta / Pictures / share /
- ls -l
ls -l displays full information about files, such as file name, size, modified date and time, the owner, and the permissions in long listing format.
Example:
O → ls -l
total 117448
drwxrwxr – x 3 ubuntu ubuntu 5094 May 10 14:13 article_images
drwxrwxr – x 5 ubuntu ubuntu 17382 May 31 2021 assignment
drwxrwxr – x 2 ubuntu ubuntu 5094 Jan 2 2021 bin
drwxrwxr – x 4 ubuntu ubuntu 5094 May 9 2021 bse
-rw – rw – r– 1 ubuntu ubuntu 0 Jan 2 2021 Cloning
- ls -F
ls -F displays files with special characters such as *, @, etc.
Example:
O → ls -F
article_images / Cloning Downloads / git / info-page-content.zip raycast.txt
assignment / Desktop / eclipse / go1.13.5.linux – amd64.tar.gz insta sampe_file.txt
bin / development / eclipse – workspace / index.php meetings / sample_assignments /
bse / Documents / en – GB / info – page – content / Pictures / share
- ls -sh
ls -sh displays the file sizes in human-readable format.
Example:
O → ls -sh
total 115M
4.0K article_images 4.0K Desktop 4.0K eclipse-workspace 4.0K info-page-content. 0 raycast.txt
16K assignment 4.0K development 4.0K en – GB 4.0K info-page-content.zip. 0 sampe_file.txt
4.0K bin 4.0K Documents 4.0K git 4.0K insta. 4.0K sample_assignments
4.0K bse 48K Downloads 115M go1.13.5.linux-amd64.tar.gz 4.0K meeting. 4.0K share
0 Cloning 4.0K eclipse 4.0K index.php 12K Pictures. 4.0K snap
- ls -lh
ls -lh displays full information about file names in human-readable format.
Example:
O → ls -sh
total 115M
drwxrwxr – x 3 ubuntu ubuntu 4.0K May 10 14:13 article_images
drwxrwxr – x 5 ubuntu ubuntu 16K May 31 2022 assignment
drwxrwxr – x 2 ubuntu ubuntu 4.0K Jan 2
drwxrwxr – x 4 ubuntu ubuntu 4.0K May 9 2022 bin 2021 bse
-rw – rw – r . 1 ubuntu ubuntu 0 Jan 2 2022 Cloning
drwxr – xr – x 12 ubuntu ubuntu 4.0K Jun 29 17:29 Desktop
drwxrwxr – x 9 ubuntu ubuntu 4.0K Jun 9 16:46 development
drwxr – xr – x 6 ubuntu ubuntu 4.0K Jun 24 12:06 Documents
drwxr – xr – x 37 ubuntu ubuntu 44K Jun 29 13:57 Downloads
drwxrwxr – x 3 ubuntu ubuntu 4.0K May 25 12:56 eclipse
drwxrwxr – x 3 ubuntu ubuntu 4.0K May 25 17:49
drwxrwxr – x 5 ubuntu ubuntu 4.0K Jani 9 2022 en – GB
drwxrwxr – x 13 ubuntu ubuntu 4.0K Feb 15 20:53 git
-rw – rw – r .. 1 ubuntu ubuntu 115M Dec 5 2021 go1.13.5 linux-and64.tar.gz
-rw – rw – r– 1 ubuntu ubuntu 19 Mar 24 2022 index.php
drwxrwxr – x 2 ubuntu ubuntu 4.0K Apr 12 2022 info-page-content
-rw – rw – r .. 1 ubuntu ubuntu. 3.6K Apr 12 2022 info-page-content.zip
drwxrwxr – x 3 ubuntu ubuntu 4.0K May 31 2022 insta
drwxrwxr – x 2 ubuntu ubuntu 4.0K Jun 6 2022 meetings
drwxrwxr – x 2 ubuntu ubuntu 12K Jun 29 17:09 Pictures
- ls -r
ls -r display all files in reverse alphabetic order.
Example:
O → ls -r
Videos solution-page-content.zip solution-info-content sample_assignments Pictures Info-page-content.zip go1.13.5.1tnux-and64.tar.gz
test.txt solution-page-content snap sample_file.txt meeting. Info-page-content.zip git
study solution-info-content.zip share raycast.txt insta. Index.php. en-GB
- ls –version
ls –version displays the version of the ls command.
Example:
O → ls –version
ls (GNU coreutils) 8.30
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3 +: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html >.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Richard M. Stallman and David Mackenzie.
- ls -ltr
ls -ltr displays a long list of files based on modification date in reverse output order.
Example:
O → ls -ltr
total 117448
-rw – rw – r .. 1 ubuntu ubuntu 120074076 Dec 5 2020 go1.13.5.11nux – and64.tar.gz
drwxrwxr – x 2 ubuntu ubuntu 4096 Jan 2 2021 bin
-rw – rw – r- . 1 ubuntu ubuntu 0 Jan 2 2021 cloning
drwxrwxr – x 5 ubuntu ubuntu 4896 Jan 9 en-GB
drwxrwxrwx 3 ubuntu ubuntu 4896 Feb 9 share
-rw – rw – r– 1 ubuntu ubuntu 19 Mar 24 index.php
drwxrwxr – x 2 ubuntu ubuntu 4896 Apr 10 solution-page-content
-rw – rw – r .. 1 ubuntu ubuntu 10566 Apr 10 solution-page-content.zip
drwxrwxr – x 2 ubuntu ubuntu 4896 Apr 12 info-page-content
-rw – rw – r– 1 ubuntu ubuntu 3616 Apr 12 info-page-content.zip
drwxrwxr – x 2 ubuntu ubuntu 4896 Apr 13 solution-info-content
-rw – rw – r .. 1 ubuntu ubuntu 3921 Apr 13 solution-info-content.zip
drwxrwxr – x 4 ubuntu ubuntu 4896 May 9 bse
drwxrwxr – x 3 ubuntu ubuntu 4896 May 31 insta
drwxrwxr – x 5 ubuntu ubuntu 16384 May 31 assignment
drwxrwxr – x 2 ubuntu ubuntu 4896 Jun 16 meetings
drwxrwxr – x 4 ubuntu ubuntu 4896 Jun 10 sample_assignments
drwxrwxr – x 13 ubuntu ubuntu 4896 Feb 15 glt
- ls -t
ls -t display files based on modification time & date, i.e.; displays the last edited file first.
Example:
O → ls -t
Desktop sample_file.txt eclipse-workspace raycast.txt meetings solution-info-content.zip solution-page-content.zip
Pictures Downloads snap study assignment solution-info-content solution-page-content
test.txt Documents eclipse git insta info-page-content.zip. index.php
Videos development article_images sample_assignments bse info-page-content. share
- ls -n
ls -n displays each file’s User ID and Group ID instead of their names.
Example:
O → ls -n
total 117448
drwxrwxr – x 3 1000 1000 5094 May 10 14:13 article_images
drwxrwxr – x 5 1000 1000 17382 May 31 2021 assignment
drwxrwxr – x 2 1000 1000 5094 Jan 2 2021 bin
drwxrwxr – x 4 1000 1000 5094 May 9 2021 bse
-rw – rw – r- – 1 1000 1000 0 Jan 2 2021 Cloning
- ls -m
ls -m displays a list of files separated by commas.
Example:
O → ls -m
article_images, assignment, bta, bse, Cloning, Desktop, development, Documents, Downloads, eclipse, eclipse-workspace, en-GB, git, got.13.5.tx-andse.tar.gz, index.php, info-page-content, info-page-content.zip, insta, meetings, Pictures, raycast.txt, sample file.txt, sample_assignments, snap, solution-info-content, solution-info-content.zip, solution-page-content, solution-page-content.zip, study, test.txt, videos
- ls -g
ls -g displays full information about files, such as file name, size, modified date and time, and permissions in long listing format by excluding the owner and group information.
Example:
O → ls -g
total 117448
drwxrwxr – x 3 ubuntu 5094 May 10 14:13 article_images
drwxrwxr – x 5 ubuntu 17382 May 31 2021 assignment
drwxrwxr – x 2 ubuntu 5094 Jan 2 2021 bin
drwxrwxr – x 4 ubuntu 5094 May 9 2021 bse
-rw – rw – r– 1 ubuntu 0 Jan 2 2021 Cloning
- ls -i
ls -i display the index number of files.
Example:
O → ls -i
402615 article_images 524302 Desktop 5646847 eclipse-workspace 399194 info-page-content 397164 raycast.txt
1979577 assignment 2490877 development 397219 en-GB 399293 info-page-content.zip 415825 sampe_file.txt
791302 bin 524307 Documents 2490899 git 1717357 insta 1717406 sample_assignments
1451139 bse 524304 Downloads 395750 g01.13.5.linux-amd64.tar.gz 1717467 meeting 2367133 share
395904 Cloning 408670 eclipse 403227 index.php 524309 Pictures 397700 snap
cd Command
The cd command is used to switch, jump, or move into another directory without typing the entire file path. cd means change directory.
Syntax: cd [Options] [Directory]
cd command can be customized with many options to differentiate the outcomes. The commonly used options in cd command are the following.
- cd /
cd / is used to switch to the root or parent directory from any other directory.
Example:
shibi@linux:~$ cd /
shibi@linux:/$ pwd
/
shibi@linux:/$
- cd ~
cd ~ is used to switch back to the home directory from any other directory.
Example:
shibi@linux:~/documens/father/stepfather$ cd ~
shibi@linux:~$ pwd
/home/shibi
abhi@linux:~$
- cd ..
cd .. is used to switch to the previous directory.
Example:
shibi@linux:~/parent/baby directory$ pwd
/home/abhi/parent/baby directory
shibi@linux:~/parent/baby directory$ cd ..
shibi@linux:~/parent$ pwd
/home/shibi/parent
shibi@linux:~/parent$
- cd ../..
cd ../.. is used to switch back multiple directories.
Example:
shibi@linux:~/parent/baby directory$ cd ../..
shibi@linux:~/parent$ pwd
/home/shibi/parent
shibi@linux:~/parent$
- cd –
cd – is used to return to previous directory.
Example:
shibi@linux:~/parent/son1/son2$ pwd
/home/shibi/parent/son1/son2
shibi@linux:~/parent/son1/son2$ cd ../..
shibi@linux:~/parent$ pwd
/home/shibi/parent
shibi@linux:~/parent$ cd –
/home/shibi/parent/son1/son2
shibi@linux:~/parent/son1/son2$ pwd
/home/shibi/parent/son1/son2
shibi@linux:~/parent/son1/son2$
- cd dir_name
cd dir_name is used to obtain the relative pathname.
Example:
shibi@linux:~/parent$ ls
son1 ‘son directory’
shibi@linux:~/parent$ cd son1
shibi@linux:~/parent/son1$
pwd command
The pwd command is used to get the full path name from the root directory to the current directory. pwd means print working directory. The exit statuses of pwd command are zero (success) and non-zero (failure).
Syntax: pwd [option]
pwd command can be customized with many options to differentiate the outcomes. The commonly used options in pwd command are the following.
- pwd -L
pwd -L displays symbolic links instead of absolute paths.
Example:
shibi@linux: ~ $ cd programs
shibi@linux: ~/~ programs $ pwd -P/home/shibi/~programs
shibi@linux: ~/~ programs $
- pwd -P
pwd -P displays the absolute path of the working directory and avoids symbolic links.
Example:
shibi@linux: ~ $ cd programs
shibi@linux: ~/~ programs$ pwd -P/home/shibi/Linux
shibi@linux: ~/~ programs$
- pwd – – version
pwd – – version is used to check the version of the system.
Example:
shibi@linux:~$/bin/pwd – -version
pwd (GNU coreutils) 8.30
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Jim Meyering.
shibi@linux:~$
- pwd – -help
pwd – -help displays the pwd command help file with a list of available options.
Example:
shibi@linux-vm:~$ pwd – -help
pwd: pwd [-LP]
Print the name of the current working directory.
Options :
-L print the value of $ PWD if it names the current working directory
-P print the physical directory, without any symbolic links
By default, ` pwd ‘behaves as if` -L ‘ were specified.
Exit Status: Returns 0 unless an invalid option is given or the current directory cannot be read.
In Command
ln command is used to create soft links and hard links between files in Linux. ln means link. It has three forms. 1st form specifies the source file and destination to be linked. 2nd form specify the source file and directory to be linked. 3rd form specifies the directory name and a file to be linked to the directory.
Syntax: ln [OPTION]… [-T] TARGET LINK_NAME (1st form)
ln [OPTION]… TARGET… DIRECTORY (2nd form)
ln [OPTION]… -t DIRECTORY TARGET… (3rd form)
ln command can be customized with many options to differentiate the outcomes. The commonly used options in ln command are the following.
- ln -v (version)
ln -v displays version details.
Example:
shibi@linux:~$ ln – -version
ln (GNU coreutils) 8.30
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Mike Parker and David.
shibi@linux:~$
- ln -v (verbose)
ln -v displays the name of each file linked.
Example:
shibi@linux: ~/ geekexample$
test_dir test_dir1
shibi@linux:~/fastexample$ echo “Hello World test 1” >> exfile2.txt
shibi@linux:~/fastexample$ echo “Hello World test 2” >> exfile2.txt
shibi@linux:~/fastexample$ echo “Hello World test 3” >> exfile2.txt
shibi@linux:~/fastexample$ ls
exfile1.txt exfile2.txt exfile3.txt test_dir test_dir1
shibi@linux:~/fastexample$ ln -v exfile1.txt exfile2.txt exfile3.txt test_dir1
‘test_dir1/exfile1.txt’ = > ‘exfile1.txt’
‘test_dir1/exfile2.txt’ = > ‘exfile2.txt’
‘test_dir1/exfile3.txt’ = > ‘exfile3.txt’
shibi@linux:~/fastexample$
- ln -h (help)
ln -h displays the ln command help file with a list of details.
Example:
shibi@linux:~/fastexample$ ls
exfile1.txt exfile2.txt exfile3.txt test_dir test_dir1
shibi@linux:~/fastexample$ clear
shibi@linux:~/fastexample$ In – -help
Usage: In [OPTION]… [-T] TARGET LINK_NAME. (1st form)
or: In [OPTION]… TARGET (2nd form)
or: In [OPTION]… TARGET… DIRECTORY (3rd form)
or: In [OPTION]… -t DIRECTORY TARGET… (4th form)
]In the 1st form, create a link to TARGET with the name LINK_NAME.
In the 2nd form, create a link to TARGET in the current directory.
In the 3rd and 4th forms, create links to each TARGET in DIRECTORY.
Create hard links by default, symbolic links with – -symbolic.
By default, each destination (name of new link) should not already exist.
When creating hard links, each TARGET must exist.
Symbolic links can hold arbitrary text; if later resolved, a relative link is interpreted in relation to its parent directory.
Mandatory arguments to long options are mandatory for short options too.
– -backup[= CONTROL] make a backup of each existing destination file
-b like – backup but does not accept an argument
-d, -f, -directory allow the superuser to attempt to hard link
directories (note: will probably fail due to
system restrictions, even for the superuser)
-f, – – force remove existing destination files
-i , –interactive prompt whether to remove destinations
-L , –logical dereference TARGETS that are symbolic links
-n, – -no-dereference treat LINK_NAME as a normal file if
it is a symbolic link to a directory
-P, – -physical make hard links directly to symbolic links
-r, – -relative create symbolic links relative to link location
-s, – -symbolic make symbolic links instead of hard links
-S , – -suffix = SUFFIX override the usual backup suffix
-t, – -target-directory=DIRECTORY specify the DIRECTORY in which to create
the links
mkdir Command
mkdir command is used to create a new file or directory. mkdir means make directory. You only need to specify the new folder’s name and verify that it does not already exist. This command is capable of simultaneously creating multiple directories and setting their permissions.
Syntax: mkdir [options] [directory name]
mkdir command can be customized with many options to differentiate the outcomes. The commonly used options in the ln command are the following.
- mkdir – -version
mkdir – -version displays version details.
Example:
shibi@linux:~/GFG $ mkdir – -version
mkdir (GNU coreutils) 8.30
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by David Makinze.
shibi@linux:~/GFG $
- mkdir -v
mkdir -v displays a message every time a new directory is created.
Example:
shibi@linux:~/GFG $ mkdir -v one two three
mkdir: created directory ‘one’
mkdir: created directory ‘two’
mkdir: created directory ‘three’
shibi@linux:~/GFG $ ls
one three two
shibi@linux:~/GFG $
- mkdir -p
mkdir -p is used to create subdirectories without reporting any error.
Example:
shibi@linux:~/GFG $ mkdir -p -v first/second/third
mkdir: created directory ‘first’
mkdir: created directory ‘first/second’
mkdir: created directory ‘first/second/third’
shibi@linux:~/GFG $ ls
- mkdir – -help
mkdir – -help displays the mkdir command help file with a list of details.
Example:
shibi@linux: ~/GFG $ mkdir – -help
Usage: mkdir [OPTION]… DIRECTORY…
Create the DIRECTORY (ies), if they do not already exist .
Mandatory arguments to long options are mandatory for short options too.
-m , – -mode = MODE set file mode (as in chmod), not a=rwx – umask
-p , – -parents no error if existing, make parent directories as needed
-V , – -verbose print a message for each created directory
-Z set SELinux security context of each created directory
to the default type
— context [=CTX] like -Z , or if CTX is specified then set the SELinux
or SMACK security context to CTX
– -help display this help and exit
– -version output version information and exit
GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
Full documentation at: <http://www.gnu.org/software/coreutils/mkdir>
or available locally via: info ‘(coreutils) mkdir invocation’
shibi@linux: ~/GFG $
- mkdir -m a=rwx
mkdir -m a=rwx is used to set the permission to read, write, and execute on the created directory.
Example:
shibi@linux: ~/GFG $ mkdir -m a=rwx
shibi@linux: ~/GFG $ ls
1png College
5555 farewell 2022-04-12 12:45:7png
linux.docx. farewell 2022-04-11 12:42:7.png
linuxfun.pdf
shibi@linux: ~/GFG $
rm Command
The rm command removes objects from the file system, such as directories, files, symbolic links, etc. rm means to remove.
Syntax: rm [options] [file_name]
rm command can be customized with many options to differentiate the outcomes. The commonly used options in the rm command are the following.
- rm -r
rm -r is used for recursive deletion. It removes all files and subfolders in the directory without asking for confirmation.
Example: rm -r home/document/games
- rm -f
rm -f is used for force deletion. It removes the file forcefully by overriding minor protection. It will not remove write-protect directories.
Example: rm -f super.txt
- rm -i
rm -i is used for Interactive deletion. It asks for confirmation from the user before removing each file.
Example: rm -i super.txt
cat Command
The cat command displays the file’s contents after reading the data. Cat means concatenate. It is used to create, view, and combine files.
Syntax: cat [options] [file_name]
cat command can be customized with many options to differentiate the outcomes. The commonly used options in the cat command are the following.
- cat -n
cat-n displays the contents of a file preceding with line numbers.
Example: cat-n will show the content of a file with a line number.
- cat >
cat > is used to create a file.
Example: cat > shibi will create a file named shibi.
- cat -v
cat -v displays non-printable characters.
Example: cat -v will display non-printable characters.
- cat -s
cat -n suppress the repeated empty line in the content.
Example: cat -n will eliminate the repeated empty line.
- cat -E
cat -E displays characters at the end of the line highlighted.
Example: cat -E will highlight the end of the line.
cp Command
cp Command is used to copy folders, files, and directories from one location to another. cp means to copy.
Syntax: cp [options] [source] [destination]
cp command can be customized with many options to differentiate the outcomes. The commonly used options in the cp command are -i (interactive), -f (force), -p (preserve), -b (backup), -a (archive), and -n (no overwrite)
mv Command
mv Command is used to move folders, files, and directories from one location to another. It performs two functions, such as moving files and renaming files. mv means to move.
Syntax: mv [options] [source] [destination]
mv command can be customized with many options to differentiate the outcomes. The commonly used options in the cp command are -i (interactive), -f (force), -b (backup), and -n (no overwrite)
Conclusion
SSH is used for logging in to a shell on a remote host, file listing, creating folders, removing files, setting up automatic logging into a remote server, tunneling sensitive data, securely and efficiently backing up, copying, and mirroring files, forwarding a port, securing file transfer protocols, etc. SSH login credentials and SSH client is required to use SSH. On Linux, a native Terminal app is used for the connection.