I'm someone who is now using Linux as my main OS but remember quite well how difficult it was to get my head around the workings of Linux my first few weeks.
So today i'm going to share a number of helpful commands to get you on your way!
Does exactly what it says on the tin.... it helps you change your directory in the company line. So for example, if you want to go into your download directory you can do the following;
You can also use the shorthand version;
The important bit of the second command is the ~ and the /
The tilde (~) is the Linux shortcut for the home directory whereas ~/ references the start of a directory in the logged in users folder.
Want to go back 1 folder? you can do the following instead of typing the whole path again:
I use this an awful lot on my server when navigating through folders to see if I'm in the right folder or not. Another thing i tend to do is use the -l option on the command to get the permissions of the files and folders. the -l option essentially means show me the long format of the list with permissions.
If you take a look at 10 lines down in the above window it shows "total 8". What this is actually doing is counting the number of files in the 2 sub folders Example-Folder-1 and Example-Folder-2
There is a fair few more options for the list command like
ls -r which will display the files in reverse order or
ls -S which will sort the files by file size.
When it says Print it means to the terminal output not a piece of paper :P other than that.... it does exactly what it says on the tin.
I use this sometimes if i need to find out what the current directory is and run a command that requires the pull path.
These 2 commands are great for quick editing through the terminal of folders.
if you use the
mkdir command it will create a folder for you with the relevant file with Read, Write & Execute rights to your user and group and Read & Execute for the "other". I'll be going through the file permissions in a future post so stay tuned.
I don't think this one needs much introduction but it does actually come with a few options.
sudo shutdown now
This shuts down the computer right now.
sudo shutdown -r now
This shuts down the computer in the correct manner and then restarts it again.
Alternatively you can use:
sudo shutdown -r 0
which does the same thing.
Want to schedule a shutdown? no problem the below command shuts down the PC in 15 minutes from when enter is hit on the command.
sudo shutdown -h 15
or if you want to shutdown at a specific time of the day you can do so by passing the 24 hour timestamp u want.
sudo shutdown 16:00
Mistype your shutdown schedule command? thats fine too... you can simply cancel it with the following command.
sudo shutdown -c
this is another handy command if you want to create empty files on your system, like if you want to create an empty text file you can do with this command.
You can also use this to create files which are hidden as standard by the Linux OS (files starting with .)
Notice that when i do the ls command the file is hidden but when i do the ls -a (all, shows hidden files) it displays the file we just created.
The commands are very hand if like me you are in and out of lots of text files in the Linux terminal. (Tail is the handier of the two)
so i have generated a file with random text in it to demonstrate the following commands.
As you can see from the screenshot when you time
head the command looks at the first 10 lines of the file (this is specified with the -n option) the same is for the tail it starts at the tail end of the document and the number of lines is specified exactly the same as the head command with a -n
I use tail a LOT on my web-server when i'm checking logs which in some cases can become thousands and thousands of lines long. Generally i only want to see the last 100 lines of a log (if you need more than that there is a serious problem :P) and what i do is output them lines to a text file on its own.
tail -n 100 headandtail.txt > lastonehundred.txt
Lets break the command down
Look at the last 100 lines of the headandtail.txt file and output the result to lastonehundred.txt
The move command is essentialy the cut tool from Windows it cuts/removes the file from its currently location and is output to the specified folder. in the previous example i tailed some text from headandtail.txt but meant to put it in the Example-Folder-1 so now i can use the mv command to do this, see screenshot below.
This command goes hand in hand with the move command in some sense but it leave a "copy" in the location its already at. as an example il copy the file lastonehundred.txt file back to the root folder.
i mean this command is very simple but helps a lot when trying to focus in the terminal. type
clear in your terminal that has lots of terminal text going on and it will remove it all and give you a terminal as if you just opened it up.
I hope these snippets have been helpful for you all! if you found this post useful please consider following me on twitter @skino2020 and if you found it really helpful consider buying me a coffee here.