Linux Commands With Examples

In today’s post I will be showing you some of the commands on Linux. While I know that this has been posted about many times in the past, a-lot of the guides that I found were missing commands or only covered the vary basic ones.

Navigating The Terminal

The commands below can be used to navigate throughout your filesystem as-well as see what files are in your different directories. There are some shortcuts such as cd .. and cd ~ that I will also show in the screenshot below this table.

pwdDisplay current working directory (which directory are you in)
cdChange directory, used to change to a different folder.
lsShow all files/directories in current folder, can also specify a folder.
ls -aSame as above except this includes hidden files.

Navigating Linux Terminal

Working With Files/Directories

These commands are useful for working with your directories and files and can do things ranging from copy a file to searching the contents of a file. One very important note to remember which I also highlighted below is that once you remove a file or directory it is gone forever.

mkdirCreate a directory if you have permission to do so.
rmdirDelete a directory, the directory must be empty.
rmDelete a file or multiple files if you use wildcards or regex.
IMPORTANT: Once deleted, forever gone!
touchCreate a blank file, you can also do this with multiple other methods.
cpCopy a file, this can be used to make a backup or just make a copy.
mvMove or rename a file, there is no actual rename command.
catDisplay the contents of a file, you can also pipe the output into other commands.
grepSearch the contents of a file for any line that contains your search string, you can use regex and wildcards as-well.
chmodChange the permissions for a file or folder, this can also be used to make a file executable.
chownChange the owner of a file/folder, by default whoever creates a file owns it.

Working With Files In Linux

Other Useful Linux Commands

Below are some of the other useful linux commands that will help you accomplish things such as rebooting, killing processes, etc.

sudoRun as super user (root), can be used to do things such as install software under your regular user account.
ifconfigLook up your networking information such as ip address, packet info, etc.
ipHas same functionality as ifconfig but more powerful, this is starting to replace ifconfig.
lastShow last users to login as-well as when system booted.
shutdownShutdown your system.
rebootReboot your system.
init 6Reboot your system.
init 0Shutdown your system.
topReal-time overview of processes and system resource usage, somewhat similar to the task manager. Exit by pressing CTRL+C.
ps auxShow list of all running processes, can be piped into grep to find specific processes.
killKill a specific process, this will not kill a zombie process but will work on most processes.
clearClears your terminal making it easier to read the output of new commands, you can also use CTRL+L to accomplish this.

Useful Shortcuts

CTRL+LClear any text or information showing in your terminal, same as running the command clear.
CTRL+DDisconnect from server or switch if you are on a remote connection.
TABBy using the tab button you can have bash guess what you mean and automatically fill it in for you, an example would be if you type in grep test /var/log/mes it will auto complete to /var/log/messages.

Final Notes

If you ever need to terminate a command or script while it is running, simply press CTRL+C to do so and you will return to your prompt. To test this for yourself simply run the command top. If you need to pipe one command into another you can do so by following the example below.

By the way a good idea when using grep to look for processes is to wrap one of the letters in the search term with brackets, this will prevent your grep command from showing up in the results.

I hope you enjoyed this guide, please do not forget to like/share as it will help the blog grow. Thank you!

Leave a Reply

Your email address will not be published. Required fields are marked *