Below you will find a summary of the most useful SSH commands.
Table of Contents
wget
The wget command is primarily used to download files directly to the server from the SSH console. This is especially useful when you want to download a package with a script to install.
For example, this command has such construct
wget https://domain.com/filename.zip uname
The uname command, short for Unix Name, will display detailed information about the Linux system, such as machine name, operating system, kernel, and so on.
You have to take into account that in the case of hosting services, the resulting information is often limited from above.
touch
The touch command allows you to create a new empty file on the Linux command line.
For example, type touch /yourdomain.com/public_html/page.html to create an HTML file named page in the yourdomain.com domain’s home directory.
tar
tar is a tool used to archive and extract archive files in this format.
Archive files generated with the help of this application, in the case of compression of a directory containing other directories and files, the directory tree, which allows it to be restored after unpacking.
Syntax:
tar -archive file options Options:
-c creates a new archive
-x will unzip the file
-t will display the contents of the archive file
-z compresses the archive using the gzip program
-r will attach files to an already existing archive
-f will indicate the file where the archive is to be saved
Examples of use:
To create an archive file named myarchive.tgz containing all the files and subdirectories in the /yourdomain.com directory, type:
tar –c –z -f myarchive.tgz /yourdomain.com
Commands for archiving files:
To extract the compressed archive named myarchive.tgz to the current directory, type:
tar -x -z -f myarchive.tgz To attach the textfile.txt file to an existing, uncompressed archive named myarchive.tar, type:
tar -r -f mojearchiwum.tar dodatkowy.txt
tail
The tail command is somewhat similar to the head command, but instead of showing the first lines, tail will show us the last ten lines of the file.
For example:
tail -n notes.txt This command is often used to extract recent references from access logs or error logs.
rmdir
If you want to delete a directory, use the rmdir command.
Note that rmdir only allows you to delete empty directories.
rm
The rm command is used to delete directories and their contents. If you want to delete only the directory – as an alternative to rmdir – use rm -r where -r means recursive deletion, so it also applies to the contents of the directory.
pwd
Use the pwd command to find out what the path to the current directory (folder) you are in. The command will return an absolute (full) path, which is basically the path of all directories starting with a forward slash (/). An example of an absolute path is /home/mybox/yourlogin.
mv
The primary use of the mv command is to move files, although it can also be used to rename files.
The arguments in mv are similar to the cp command. You need to enter the mv, file name, and destination directory. For example:
mv file.txt /destination-directory. To rename files, the Linux command is
mv oldname.txt newname.txt passwd
passwd – change the user’s password. If you do not specify the name of the user for whom the password is being changed, the password of the user from whose account the command was issued will be changed.
Syntax:
passwd username Examples of use:
Change password for login-mybox
passwd login-mybox account
mkdir
Use the mkdir command to create a new directory – if you type
mkdir newdirectory it will create a directory named newdirectory.
There are also additional mkdir commands:
To create a new directory inside another directory, use this command mkdir directory-1/directory-2
use the p (parents) option to create a directory between two existing directories. For example,
mkdir -p directory-1/2020/directory-2 will create a new file “2022”.
ls
The ls command is used to browse the contents of the directory. By default, this command will display the contents of the current working directory.
If you want to see the contents of other directories, type ls and then the path to the directory. For example, type ls mydomain.com to view the contents of the mydomain.coml directory.
There are variants that you can use with the ls command:
ls -R will display all files that are also in subdirectories
ls -a will show hidden files
ls -al will display a list of files and directories with details such as permissions, size, owner, etc.
man
Have doubts about the functionality of some Linux commands? Don’t worry, you can easily learn how to use them directly from the Linux shell using the man command. In this case, Man is an abbreviation for manual, i.e. a user manual.
For example, typing man tail will show the manual for the tail command.
history
When you use Linux for a period of time, you will quickly notice that you are giving a lot of commands every day.
Issuing the history command is especially useful if you want to review commands that have been used before.
head
The head command is used to display the first lines of any text file.
By default, it shows the first ten lines, but you can change this number to your liking.
For example, if you want to display only the first five lines of a notes.txt file, issue the command
head -n 5 notes.txt. find
Using the find command searches for files and directories within the directory you’re currently in.
For example, the command find ~/-name notes.txt will search for a file named notes.txt in the home directory and its subdirectories.
Other variants of using find are:
To find files in the current directory use,
find .-name notes.txt To search directories use,
find /-type d -name notes.txt grep
A Linux command that is undoubtedly helpful in everyday use is grep. It allows you to search all the text in a given file.
To illustrate, the grep login command will notes.txt search for the word login in the notes.txt file.
Lines that contain the search word will be displayed in their entirety.
diff
Command is an abbreviation of the word difference.
diff compares the contents of two files line by line. After analyzing the files, it lists those lines that do not differ from each other.
Developers often use this command when they need to make changes to a program instead of rewriting all the source code.
The simplest form of this command is
diff file1.txt file2.txt cd
To navigate through files and directories in Linux, use the cd command. It requires either the full path or the directory name, depending on which directory you are currently in.
Let’s say you’re in /home/mybox/yourlogin/domain.com/public_html and you want to go to wp-content, which is a subdirectory of public_html. To do this, simply type the following command: cd wp-content.
Another scenario is if you want to go to a completely new directory, such as /home/mybox/yourlogin/anotherdomain.com/public_html. In this case, you need to type cd and then the absolute path to the directory:
cd /home/mybox/yourlogin/anotherdomain.com/public_html or if you are operating within the same home directory, you can also go a level higher by using two dots i.e .
cd .. /anotherdomain.com/public_html There are a few shortcuts to help you navigate quickly:
cd.. (with two dots) to move up one directory
CD to go directly to the home folder
cd- (with hyphen) to go to the previous directory
The Linux shell is case-sensitive. So, you need to type the directory name exactly as it is.
cp
Use the cp command to copy files from the current directory to another directory.
For example, the command
cp photo.jpg /photos will create a copy of the photo.jpg file (from the current directory) to the photo directory.
cat
cat (short for concatenate) is one of the most commonly used commands in Linux. It is used to list the contents of a file on standard output (stdout).
To run this command, type cat, followed by the file name and its extension. For example: cat file.txt.
Here are other ways to use the cat command:
catfilename > creates a new file
cat file-1 file-2>file-3 combines two files (1 and 2) and saves their output in a new file (3)
cat filename | tr a-z A-Z >file.txt to convert the file to uppercase or lowercase If you don’t already have an active SSH access option, click HERE for a guide.