To start using command line commands in Linux you’ll run Terminal, XTerm, or similar application.
If you need help with a command, you can type in the command man
. This will provide an online manual for the command in question. For example, you would type in the following for help on the ls command: man ls
Ls
The ls
command will list directory contents, similar to the dir
command in Windows. The resulting list may be color coded where blue is a directory and white is a file, etc.
For more detailed information, such as listing file ownership and permissions, you can use: ls -l
For commands that result in a long list, you can add a pipe (|) and more to create a paginated list for easier viewing. For example, to paginate the ls -l
command, it would be: ls -l | more
. To exit out of the pagination, press q or Ctrl-c.
Grep
The grep command allows you to search for text within a file. The search can be done for multiple files at a time. The syntax is: grep <pattern you are searching for> [FILE]
. For example, if you were looking for the word “passed” in the ComptiaAPlus.txt file, the command would look like this: grep passed ComptiaAPlus.txt
Note that the pattern is case sensitive, so in the previous example, it will only find “passed” and not “Passed.”
Cd
The cd command allows you to change from one directory to another. This is almost identical to the cd command in Windows, except that Linux uses forward slashes instead of back slashes.
The syntax looks like cd <name of directory>
. For example, to go to the default location of the log files, you would type in the command: cd /var/log
Shutdown
The shutdown command requires elevated permissions. It does exactly what it sounds like, and shuts the system down. You can specify when you want the system to shutdown. For example, if you run the command: sudo shutdown 5
, the system will shut down in 5 minutes.
To reboot the system, you would use the shutdown command with the -r options. For example: sudo shutdown -r 5
To cancel an impending shut down you can press Ctrl-C or type in the command shutdown -c
pwd vs. passwd
The pwd command stands for Print Working Directory. It lists the current working directory path. This is helpful when you have been changing directories and have forgotten in which directory you are currently located.
The passwd
command changes passwords for user accounts. The syntax is passwd [username]
. For example to change the password for Bob’s account you would enter the command: passwd Bob
To change the password for the current account you can just enter the command passwd