Top 10 Linux Commands Anyone Can Use
As we continue to find Linux loaded on more and more consumer-based PC’s the reality of Linux everywhere has come to fruition. I’m relatively excited that Ubuntu is being endorsed by companies like Dell. As more and more PC’s ship with Linux pre-loaded it’s almost necessary to become acquainted with the Linux shell. For those of you from the Microsoft days I would almost consider the Linux shell to be the DOS of Windows 3.1/95/98 (WinXP just emulated the shell). In the blurb below I try to make correlations to Windows commands to help you grasp what each command does.
Anyway, here ten of the commands I think you should know when using Linux as a first-time user. Note that when typing these commands the # sign symbolizes the shell prompt and you shouldn’t type it
I think the first command anyone should know is man. Man is short for "manual". This command provides you with details about any command (You can even "man man" from the command). Think of this as the F1 key in your standard Windows installation.
# man <command>
# man ls
Type "q" on the keyboard to exit.
Now that we know how to see what commands do, we need to know how to see files on the file system. The ls command shows you a listing of all files in a given directory. If no directory is specified, the command returns a listing of files and directories in the current working directory (CWD). Specify a directory after ls and receive a listing of that directory.
# ls <directory,optional>
# ls /etc
If you want to hang with the pros you should probably take a short amount of time and pick up vi. VI is the Linux text editor of choice for the command line. Think of VI as your quick notepad in Windows. Specify a file after the vi command to open the file. Use the arrow keys to navigate the text file.
Use the following basic commands to navigate vi:
a.) /<search string> (searches for a string)
b.) :w (writes the open file)
c.) :q! (quit without saving changes)
d.) :wq (write changes and quit)
e.) :q (quit vi)
Type "i" to enter editing mode. Hit escape after making your changes to enter the commands above.
# vi <file to edit>
# vi /etc/fstab
Have you ever lost it? What if you never had it? Enter find. Find’s only similarity, to that annoying puppy in Windows XP, is that it will find your files. Other than that, this utility does its job effortlessly.
# find <path> -name <name of file>
# find / -name foo.txt
(This command finds "foo.txt" anywhere starting with the root "/" of the file system)
This utility shows the contents of a given file. Think of this command as the Windows equivalent "type". Specify the name of the file you wish to display after the command and … presto!
# cat <file to output>
# cat /etc/fstab
This command receives input from STDIN (Standard Input) and allows you to page through the output. This is useful with the command mentioned above. What if you have too much data for your shell’s output buffer? You can’t scroll up. Enter less. Simply pipe the output of your program to less and it’ll show you a scrollable, searchable result. Use the space part to page down. Use the arrow keys to navigate up and down and type "/<search string>" to search.
# <command> | less
# cat /etc/exim.conf | less
Grep allows you to search a file for a string. It’s very simple to use. After executing your grep, each line is printed which matches your string.
# grep "string" <file>
# grep "sda" /etc/fstab
- rm, cp and mv
Here are a few commands you can’t live without: rm, cp, and mv.
Windows Command Linux Equivalent del rm copy cp rename/move mv
To remove a file use this syntax:
# rm <file>
To remove a directory and its files contained:
# rm -rf <path to directory>
To copy a file simply use the following syntax:
# cp <source> <destination>
To rename or move a file use the following syntax:
# mv <source> <destination>
PS or "process list" shows you a list of all running processes. The commonly used (at least for me) command with flags is:
# ps aux
This command shows you a list of all processes, which user they are running as and the command (truncated).
Linux is a very secure Operating System. Its roots of security lay in its strict ACL (Access Control List) settings. Linux uses chmod (change file access permissions) and chown (change file owner and group) to modify user settings and ownerships.
There are many ways to use chmod but we’ll explain the simplest.
# chmod <modes> <file/directory>
If we were to create a shell script and we wanted to set it executable we would perform the following chmod:
# chmod +x script.sh
If we wanted to set the file read/write/execute we could use this command:
# chmod +rwx script.sh
Chown simply changes the owner and/or group of the file. The old way of changing the ownerships was like this:
# chown user.group <file/directory>
To the best of my knowledge this command works but it is a bit outdated. Now simply replace the "." with ":" so the command looks like this:
# chown user:group <file/directory>
I want to change /etc/fstab to be owned by user award and group foogroup. (Don’t do this really hehe!) I would use this command:
# chown award:foogroup /etc/fstab
There are quite a few commands available in the Linux world. It’s always a good idea to be comfortable with the command line. The command line becomes easier as you use it (I’ve been living in it for almost 10 years now). The power and flexibility the command line offers is unmatched by any GUI. As with everything I recommend that you learn something from the inside out. That being said, start out with the command prompt and play around. Load up a VM (Virtual Machine) with Ubuntu or CentOS and play around. Check out this article to see how to load VMware Server Beta and get started today.