Introduction to Linux commands
Here are some warm-up exercises for those new to using the Linux command line. Be careful, it can get addicting!
If you’re new to Linux, or if you’ve just never bothered to explore the command line, you might not understand why so many Linux die-hards are enthusiastically typing commands into the terminal when they are could use a bunch of tools and apps to do this for them. Here are some of the command line wonders that might get you hooked on Terminal.
To use the command line, you must first launch a command tool, also known as a “command prompt”. The way to do this depends on the version of Linux you are using. For example, on RedHat, an “Activities” tab, visible at the top of the screen, opens a list of options and a small window to enter a command (“cmd” will open the window). On Ubuntu and other systems, a small Terminal icon is visible on the left side of the screen. On many systems, pressing “Ctrl + Alt + t” opens a command window. Finally, by connecting to a Linux system using a tool like PuTTY, you can directly access the Terminal.
Once in the command line window, the user is faced with a prompt either in the form of a simple “$” or something more elaborate like “user @ system: ~ $”. In any case, this means that the system is ready to carry out your commands.
When we get to this point, we can start writing commands. Below are a few commands for you to test first. To complete, you can easily find lists summarizing and explaining the most important commands of Linux.
The main commands
pwdIndicates where we are in the filesystem (first, this will be your home directory)
lsDisplays files in a directory
ls -aDisplays an even longer list of files (including those that start with a period)
ls -alDisplays a list of all files with many details (including dates, file size and permissions)
whoIndicates who is logged in (don’t be surprised if it’s just you)
dateRecalls the current date (also indicates the time)
psDisplays the running processes (can be reduced to shell and to order « ps »)
Once you get used to the Linux command line, there’s nothing stopping you from expanding your explorations.
For example, commands like the following can help you navigate the file system:
cd /tmpUsed to move to another directory (in this case /tmp)
lsShow files here
cdReturns to the user’s directory (without argument, the command cd always brings you back to your directory)
cat .bashrcDisplays the contents of a file (in this case, .bashrc)
historyShows recent order history
echo “hello »Attach ” Hello “
calDisplays the calendar for the current month
To better understand why advanced Linux users love the command line so much, you might want to experiment with other features, like redirect and pipes. Redirection is taking the result of a command and including it in a file instead of displaying it on the screen. Pipes are commands which send the result of a command to another command which will exploit it in one way or another.
Here are some commands you can try:
echo “echo hello” >trymeCreate a new file and add « echo hello » to this one
chmod 700 trymeMake the new file executable
trymeExecute the new file (should run the command in it and display “hello”)
ps toShows all running processes
ps to | grep $ USERShow all running processes, but limit output to lines containing your username
echo $USERDisplay your username using an environment variable
whoamiDisplays your username with a command
who | wc -lCounts currently logged in users
Once you get used to the basic commands, you can explore other commands and try writing scripts. You may find that Linux is much more powerful and more fun to use than you realize.