There are many Linux commands that can be used to help manage and optimize a system.
Knowing your Linux commands is important because they allow you to interact with your system in an efficient way. You can use them to manage files, directories, processes, and more. These commands are even more important because they can be used to automate tasks. This can help you to save time and work more efficiently.
The commands below need to be known if you’re a newbie to “nix” and want to improve your skill set. For the “nix” veteran consider this just a refresher or add your own input. So, let’s get started, shall we?
1. ls
The ls (list) command is used to list files or directories in Linux and other Unix-based operating systems.
Example usage:
[root@araxis ~]# ls
cpanel-skel csf error_log imav-deploy.sh kernelcare-latest.rpm maldetect old-cpanel-modsec-rules-from-vendor-system perl security tmp vendor
To see other ways to use the ls command then simply type "ls --help" without the quotes.
2. cd
The cd (change directory) command is used to change the current working directory that the user is currently working.
Example usage:
[root@araxis ~]# cd /tmp
[root@araxis tmp]#
To see other ways to use the cd command then simply type "cd --help" without the quotes.
3. mv
The mv (move) command is used to move files within a Unix-based system from one place to another. This command can also be used to rename files and folders.
Example usage:
[root@araxis etc]# mv host.conf.old.1593025688 /tmp
[root@araxis etc]# cd /tmp
[root@araxis tmp]# ls
abrt
host.conf.old.1593025688
mysql.sock
If we wanted to rename the tmp folder from above to the file being moved we would simply had used:
[root@araxis etc]# mv host.conf.old.1593025688 tmp
To see other ways to use the mv command then simply type "mv --help" without the quotes.
4. mkdir
The mkdir (make directory) command is used to create new directories in dos (windows), Unix-based, IBM OS/2, ReactOS, and DR FlexOS. It is also used in the EFI Shell and the PHP scripting language.
Example usage:
[root@araxis tmp]# mkdir test
[root@araxis tmp]# ls
abrt
host.conf.old.1593025688
mysql.sock
test
To see other ways to use the mkdir command then simply type "mkdir --help" without the quotes.
5. rm
The rm (remove) command is used to delete files. !!WARNING!! This command is unique in the fact that it is very dangerous. Files that are removed with this command cannot in most cases be recovered.
Example usage:
[root@araxis tmp]# ls
abrt
host.conf.old.1593025688
mysql.sock
test
[root@araxis tmp]# rm -r test
rm: remove directory ‘test’? yes
[root@araxis tmp]# ls
abrt
host.conf.old.1593025688
mysql.sock
[root@araxis tmp]#
To see other ways to use the rm command then simply type "rm --help" without the quotes.
6. echo
The echo (as the name sounds) command is used in a Unix/Linux environment that displays lines of text or string which are passed as arguments on the command line.
Example usage:
[root@araxis tmp]# echo Hello, you!
Hello, you!
To see other ways to use the echo command then simply type "echo --help" without the quotes.
7. cat
The cat (concatenate) command is used to view the contents of a file or files without having to open them for editing.
Example usage:
[root@araxis tmp]# ls
abrt
mysql.sock
examplefile.txt
host.conf.old.1593025688
[root@araxis tmp]# cat examplefile.txt
This is an example file that you're viewing. [root@araxis tmp]#
To see other ways to use the cat command then simply type "cat --help" without the quotes.
8. man
The man (manual page) command is used to view the reference manuals for commands and utilities within the Linux environment.
Example usage:
[root@araxis tmp]# man -f echo
echo (1) - display a line of text
echo (1p) - write arguments to standard output
echo (3x) - curses input options
[root@araxis tmp]#
To see other ways to use the man command then simply type "man --help" without the quotes.
9. pwd
The pwd (print working directory) command is used to print the current working directory.
(the directory that the user is currently working within)
Example usage:
[root@araxis tmp]# pwd
/tmp
[root@araxis tmp]#
To see other ways to use the pwd command then simply type "pwd --help" without the quotes.
10. cp
The cp (copy) command is used for copying files and directories to another location within the Linux environment.
Example usage:
[root@araxis tmp]# ls
abrt
mysql.sock
examplefile.txt
host.conf.old.1593025688
[root@araxis tmp]# cp examplefile.txt file_backup
[root@araxis tmp]# ls
abrt
mysql.sock
examplefile.txt
file_backup
host.conf.old.1593025688
[root@araxis tmp]#
To see other ways to use the cp command then simply type "cp --help" without the quotes.
11. ln
The ln (link) command is used to create hard links or symbolic links between files within a Unix/Linux system.
Example usage:
[root@araxis tmp]# ln test.txt targetfile.txt
This command will create a hard link from test.txt to targetfile.txt. The name of the link is, "targetfile.txt."
To see other ways to use the ln command then simply type "ln --help" without the quotes.
12. less
The less (as it sounds) command is a Linux terminal pager that displays a file’s contents one screen at a time.
Example usage:
[root@araxis tmp]# less examplefile.txt
This is an example file that you're viewing.
examplefile.txt (END)
Press q to exit this screen once you're done viewing the file.
To see other ways to use the less command then simply type "less --help" without the quotes.
13. grep
The grep (global regular expression print) command is used to search regular data within the targeted file in search of a match.
Windows has a similar command invoked by using ctrl-f within a text file.
Example usage:
Search within the targeted file examplefile.txt for the word, "example."
[root@araxis tmp]# grep example /tmp/examplefile.txt
This is an example file that you're viewing.
[root@araxis tmp]#
To see other ways to use the grep command then simply type "grep --help" without the quotes.
14. tail
The tail (as it sounds) command will display the last lines of a file. By default, it will show the last 10 entries within a given file. This of course can be modified by adding arguments to the command.
Example usage:
[root@araxis tmp]# tail examplefile.txt
This is an example file that you're viewing. [root@araxis tmp]#
To see other ways to use the tail command then simply type "tail --help" without the quotes.
15. ssh
The ssh (Secure Shell or Secure Socket Shell) command is used to create a secure encrypted connection to a host machine over an insecure network.
(Most commonly used to connect via command line to a dedicated server etc.)
Example usage:
you would use a client program such as putty complete with encryption keys to establish the connection to your servers ip address. You will normally see the screen asking for the login name and if correct then it will proceed to the password. (Nowadays ssh is usually hidden and a key will already be installed within the client program such as putty to avoid typing in a password. Which is the preferred method to avoid hack attempts.)
To see other ways to use the ssh command then simply type "ssh --help" without the quotes.
16. reboot
The reboot (as it sounds) command is the most direct way to restart a Linux or Windows machine.
Example usage:
There are many different commands to iniate a reboot for the machine. The one we typically use is, "reboot now." (without the quotes.) The machine will immediately "force" a reboot without report. Some Linux systems will print a report and others will not.
To see other ways to use the ssh command then simply type "ssh --help" without the quotes.
17. poweroff
The poweroff (as it sounds) command issues an acpi signal via the command line for the machine to shut down.
(Be sure to have some kind of kvm setup if sending this signal to a remote server.)
Example usage:
[root@araxis ~]# poweroff
(That is it and the machine will close all ssh connections and shutdown.)
To see other ways to use the poweroff command then simply type "poweroff --help" without the quotes.
18. vim
The vim (Vi IMproved) command with roots going back to the Amiga is basically the “notepad” program of a Unix device. This is a very powerful editor for any file you request to open.
Example usage:
[root@araxis tmp]# vim examplefile.txt
This is an example file that you're viewing.
~
~
~
~
"examplefile.txt" [noeol] 1L, 45C
You can type :help for assistance within vim itself.
Switch to the command mode by pressing esc (escape key) Type : (colon) to open the prompt bar.
Type w to save changes you have made to the file without exiting. To save changes and exit the program then type x instead of w.
To see other ways to use the vim command then simply type "vim --help" without the quotes.
There are many other Linux commands, but these are some of the most basic and important ones. With a little practice, you’ll be able to use them like a pro!