1and1 Help Centre Categories

print article

Common SSH Commands

The following are a few basic and important commands that can be used in SSH:
Command Description
--help --help is actually an option for all Linux commands. Use the option after any Linux command such as ftp --help which will display additional help about using the command.
man ftp Opens the manual for the given command (in this case, the ftp command). This is your second go-to place for help if using the --help option was not specific enough. The man(ual) page for commands will show additional information like a summary of the command's function, the correct syntax, available options for the command with a short description, etc.
pwd print working directory will show you the full path or entire folder hierarchy down to the folder where you are currently working. /kunden/homepages/30/d339629174/htdocs/wordpress for example, means that you are currently working in the wordpress folder. The htdocs folder is your "home folder" or "root of your webspace." Any folder before the htdocs/ folder cannot be edited or accessed.
ls list the subdirectories (subfolders) and files in the current folder.
cd folder1 Relative change directory command to change folders. The folder specified must be a subfolder of the current location. The example will change to the subfolder named "folder1". Use the ls command to view subfolders.
cd /kunden/homepages/30/d339629174/htdocs/wordpress Absolute change directory command to change folders. This is the same command as above, except this time the "full path" or complete folder hierarchy is supplied.
cd .. change directory to the "parent" of the current folder. The parent folder is the opposite of a subfolder.
cat document1.txt document2.txt Concatenates (links together) two text files named "document1.txt" and "document2.txt" and outputs the text of each to the screen in a series.
cat document1.txt Same command as above but this time only one document is supplied. The result is the text of document1.txt is linked with nothing and the command outputs the text of document1.txt to the screen.
less document.txt Similar to the cat command which can output the text of a document however the less command displays only enough text to fit the screen. This allows you to use the up and down arrow keyboard keys to scroll through longer text files.
mkdir newdir Makes a new directory (creates a new folder) named "newdir".
nano document.txt Opens the nano text editor to edit or view text files. Once the nano text editor has been opened. Additional commands are listed at the bottom of the screen. The exit command is listed as ^X for instance which signifies to hold the Ctrl key and then press the x key to exit the text editor.
rm filename.txt Removes (deletes) the file named "filename". (Please use this command with caution. Once the file is deleted there is no way to restore it.)
mv filename.txt subfolder1/filename.txt Moves the text file "filename.txt" to the subfolder "subfolder1" keeping the same filename.
mv oldFilename.txt newFilename.txt Renames the file "oldFilename.txt" to "newFilename.txt" in the same directory. The example states to move the file "oldFilename.txt" from the current forlder, to the current folder and save it as "newFilename.txt" thus renaming it.
tar -czvf filename.tar.gz folder1/ Creates a tar.gz file named filename.tar.gz containing all contents (files, subfolders, etc) of the "folder1" folder.
tar -xvf filename.tar.gz Uncompressing a tar.gz file.
zip newZipFile.zip fileToZip1.txt subfolder1/fileToZip2.jpeg Creates a zip file named "newZipFile.zip" which includes fileToZip1.txt from the current folder and fileToZip2.jpeg from the subfolder named subfolder1.
unzip filename.zip Unzips the filename.zip file into the current folder.
Tips for the 'ls' command

The list or ls command is used quite often to list the files and subfolders of the current folder. Using options with this command can be of great use. Try the

ls

command first and then try the following command:

ls -lahp --color=always

See the difference:

ls command
ls command
ls -lahp --color=always command
ls -lahp --color=always command

As you can see, much more info is displayed using options for the list command line. You could type the

man ls

command to bring up the manual for the list command and see what each option used actually does, but here is an overview:

ls command option Explanation
l Lists the files and subfolders in long format. This will display the permissions, number of subfolders, owner, group, size, and last date modified of the files/folders.
a Lists all the files and folders. Using this option will display hidden files (files beginning with a period(.).
h This command is used in conjunction with the long option to display the file sizes in human-readable format (Kilobytes, Megabytes, Gigabytes, etc.). When using the long option with out the human-readable option, file sizes will be listed in bytes such as "11320327" instead of "11M" which is harder to read.
p Lists folders with an appending slash(/) so folders are easier to recognise in the listing.
--color=always Uses colour for files and folders depending on their permissions, file extension, etc.

Listing files with a trailing slash for folders and using colours should help just about everyone when dealing with a long listing of files. Typing out

ls -p --color=always

each time you want to list the contents of a folder with trailing slashes and colours seems bothersome though. Luckily, there is another useful command to help us out!

Tips for the 'alias' command

The alias command allows us to make essentially a shortcut for a command with options. We can create an alias for

ls -p --color=always

and name it "list" for example. The every time you would type out

list

and press enter, it would then run the following command:

ls -p --color=always

That would really make things easier as it is a lot less to type.


To make an alias simply use the alias command like below:

alias list='ls -p --color=always'

Now you can just type

list

and press enter to get a file listing with a trailing slash after folders and in colour!

For additional information, you may want to reference: