This article is an introduction to finding your way around your server in SSH.
- Hit Enter or Return after every command unless specified otherwise.
- The domain example.com should always be replaced with your own domain name.
- Example paths and file names should also be replaced with your own server information.
The tutorial will assume that:
- You have enabled SSH user which is eaither root or a sudo user.
- You have an ssh terminal ready available and open to login to the server from vpsserver.com.
- You should have an open command prompt.
When first logging into the server this will be your first directory.
or if you are not a root user:
/bin : All the executable binary programs (file) required during booting, repairing, files required to run into single-user-mode, and other important, basic commands viz., cat, du, df, tar, rpm, wc, history, etc.
/boot : Holds important files during boot-up process, including Linux Kernel.
/dev : Contains device files for all the hardware devices on the machine e.g., cdrom, cpu, etc
/etc : Contains Application’s configuration files, startup, shutdown, start, stop script for every individual program.
/home : Home directory of the users. Every time a new user is created, a directory in the name of user is created within home directory which contains other directories like Desktop, Downloads, Documents, etc.
/lib : The Lib directory contains kernel modules and shared library images required to boot the system and run commands in root file system.
/lost+found : This Directory is installed during installation of Linux, useful for recovering files which may be broken due to unexpected shut-down.
/media : Temporary mount directory is created for removable devices viz., media/cdrom.
/mnt : Temporary mount directory for mounting file system.
/opt : Optional is abbreviated as opt. Contains third party application software. Viz., Java, etc.
/proc : A virtual and pseudo file-system which contains information about running process with a particular Process-id aka pid.
/root : This is the home directory of root user and should never be confused with ‘/‘
/run : This directory is the only clean solution for early-runtime-dir problem.
/sbin : Contains binary executable programs, required by System Administrator, for Maintenance. Viz., iptables, fdisk, ifconfig, swapon, reboot, etc.
/srv : Service is abbreviated as ‘srv‘. This directory contains server specific and service related files.
/sys : Modern Linux distributions include a /sys directory as a virtual filesystem, which stores and allows modification of the devices connected to the system.
/tmp :System’s Temporary Directory, Accessible by users and root. Stores temporary files for user and system, till next boot.
/usr : Contains executable binaries, documentation, source code, libraries for second level program.
/var : Stands for variable. The contents of this file is expected to grow. This directory contains log, lock, spool, mail and temp files.
CHANGING CURRENT DIRECTORY
You can change the current directory with cd command.
To go back to the home directory:
To go to the parent directory supposed you are in the directory /etc/sample/items/:
Will bring you to etc/sample/.
DISPLAY YOUR CURRENT DIRECTORY
To display your current directory use the pwd command.
LIST CONTENT OF A DIRECTORY
To list the files and folder in a directory use ls command.
To show hidden files use:
To display the content of a directory with formats and size use:
To display the size of files in a directory with human readable format use:
CREATE/REMOVE A DIRECTORY
To make a directory we execute the mkdir command.
To make a directory within a non-existing parent directory:
mkdir -p /root/notexists/newdir
To remove a directory:
To remove a directory recursively:
rmdir -p /root/notexists/newdir
CREATE/REMOVE A FILE
To create an empty file we use touch.
To remove a file forever:
To prevent yourself from accidentally removing a file:
rm -i /root/sample.txtThen it will ask you a question if you really want to remove this particular file.
COPY A FILE OR DIRECTORY
To copy a file we execute the cp command.
cp /root/sample.txt /root/newfile.txt
To copy complete directory:
cp -r /root/olddir /root/newdir
To prevent cp from overwriting existing files accidentally.
cp -i /root/sample.txt /root/newfile.txt
Then it will tell you that the file exists and if you want to overwrite the file.
RENAME/MOVE A FILE OR DIRECTORY
Use mv to rename a file or to move the file to another directory.
To rename a file:
mv file12.txt file31.txt
To rename a directory:
mv olddir newdir
To ask permission to rename a file:
mv -i file1.txt file20.txt
WORKING WITH FILE CONTENT
To display first 10 lines in a file.
To display the first n lines in a file:
head -5 file23.txt
Will show the first 5 lines in a file.
To display the last 10 lines in a file:
To display the last n lines in a file:
tail -15 file1.txt
Will display the last 15 lines in a file.