Basic Linux commands (Part 1)
If you’re new to Linux then you’re going to need to get to know the command line and some of the basic Linux commands you can use to achieve the goals you set. In this guide we’re going to go into a few very basic command you would use in your day to day activities. This guide is good for anyone with a Linux VPS or dedicated server and should work on any version of Linux from CentOS to Debian and Fedora.
To change to a different directory once logged into ssh you can issue the cd command followed by the path to the folder you want to be in for example if you wanted to change to a cPanel users home directory and the user was called first2host you would issue the cd command followed by the path to the required directory.
Here we issued the cd command followed by the absolute path to the user’s directory. This is confirmed by the second line we can see [/home/first2host] which shows our current directory location.
Listing files in a directory
Now we know how to change into different directories your likely going to want to know what’s in these directories. This is done by issuing the ls command from inside the directory you wish to see inside. We’re already in the users first2host directory so let’s see what’s in there.
By issuing the ls command we can now see all the files and directories inside this folder in alphabetical order. If you wanted to have this arranged by size which is good for freeing up space then you would issue;
Now you can see all the files in this directory listed in order of size.
Creating a file
To create a file you can either use touch or a program like nano or vi. If you wanted to create a text document in your home directory. You could just issue nano /home/first2host/file1.txt. That will create the file and open the document ready for you to work inside. You can also use touch to do the same job but this doesn’t open the document to work inside.
nano /home/first2host/file1.txt touch /home/first2host/file2.txt
Removing a single file
To remove a single file from the server you can use the rm utility. This only removes files not directories with files in them
rm -f file1.txt
Next, if we issue the command to list the directory contents you can see that file has now been deleted
You can also delete a file by using just rm and the file name. This will prompt you to confirm the file deletion with either a “y” or “n”.
Copying a file
You will also need to copy a file from time to time. For example, if your making edits to a file its always a good idea to have a backup. Let’s copy a file from our user directory. Then we can place that file into a folder called backup inside our user directory
cp file2.txt /home/first2host/backup
Now we can enter and list the backup file contents
cd /home/first2host/backup ; ls
Creating a directory
You can create any directory or folder you wish using the mkdir command. As we are already in our backup directory we will make a folder called hello. Then we will issue the ls command to see the new directory, you could then cd into this new folder.
Downloading a file to your server
You can use the wget feature from the command line to download a file to your server. This can be any file and any file type as long as it’s accessible via http or https. We’re going to grab a copy of our cPanel installer
You can use wget to get of copy of files onto your server. If you don’t specify a location for the file after the URL The file will be placed into your current directory. To place the file into /home you would issue this command
wget https://first2host.co.uk/servers/cpanelinstall.sh /home
Executing a file
Some files can be run, just like a program on a Windows computer but without the graphical interface. Our file above is an sh file so we know this is likely to be a script, in fact, it’s our own in-house cPanel install script. If we run the below command that will start the script
You must be in the same directory as the file or script to for the command to run like this. You can also specify the path to the script if you know it without having to change directory
How was this article? – Basic Linux Commands
More from All About Linux
Ioncube Loaders are a piece of software that is used to protect the underlying code in PHP applications. Its aim …