7 Extremely Useful Linux Commands
Posted by on 01 November 2018 12:11 PM
#1: ls : What’s in this directory?
The command ls stands for list directory contents. And, cleverly, it will do just that: list a directory’s contents! Using it with -F will give a list of the directories contents, and denote items that are other directories with a trailing /.
On my server returns:
In the above case, allthethings.txt, garbage.file, important.doc, and probs.xlsare files, and Indominus, Misc, Red Wings, Spreadsheets, and Work, each with the trailing /, are directories!
There are many other options, or switches, such as -F that can be used with ls for improved results. For example:
In the above case two switches are added: -l and -a. The -l uses the long listing format, and the -a switch lists all of the files, including hidden files.
Each column contains an important bit of information:
Column | Information | Example
Before deleting anything, it’s always helpful to know what directory you’re in; the pwd command will tell you and stands for present working directory:
Returns the full path name:
Checking the present working directory can prevent errors when you’re using commands that will remove files or directories… in fact, it can save you from a lot of stress and headache!
#3: cd : Move me to this other directory! Stat!
The cd command stands for change directory and is used extremely frequently.
For example, if you’re currently in your home directory /home/dinosaursareawesome:
but want to change to another directory withing that directory… say… Velociraptor:
Then you can use the following command to change to Velociraptor:
And then verify that you made it to the right directory:
#4: touch : Create this file, or update the timestamp on that file!
The touch command is generally used to change file timestamps, but it can also be used for creating a new file.
Let’s look at changing a time stamp first. In the case below, I have a file named Foxtrot in the current directory, that was created on Apr 14 12:46:
Now, let’s say I wanted to update that timestamp, Apr 14 12:46 to the current timestamp, but without changing the file. Simply touch the file:
And then check the new timestamp and you’ll see it has been updated to the current time, which for me is Apr 17 17:01:
The second use of the command is to create a file. Let’s say I wanted to create the file Golf in my present working directory:
Now look for your new file:
#5: history : What have I done and with which commands?
The history command will print a history of all the previously executed commands by the current user. For example:
#6: uname : What version am I running?
The uname command is most commonly used to determine which OS you’re running, its version, and the kernel version. With the -a switch, it will show: 1. kernel name, 2. network node hostname, 3. kernel release, 4. kernel version, 5. machine hardware name, processor type or “unknown”, 6. hardware platform or “unknown”, and 7. the operating system.
#7: man : Help! What does this command do?!
The man command opens manual pages for individual commands; basically, it’s your access to quick information on any command. For example, if you wanted to read the manual page for ls, then you would run: