These 25 commonly used commands are ideal for newcomers who want to get started on the Linux command line. Credit: 1 Getting started on the Linux command line might seem overwhelming at first, but the many commands you need to use will fall into place more quickly than you might imagine. Let’s start with some introductory but very important commands. First, when you open a command terminal or log into a remote Linux server, you will be sitting at the command prompt. This might be just a $ or might be something as complex as [george@system ~]$ that will change as you move from one directory to another. You, however, will be located in your home directory. The first commands you will need to know include pwd and ls. 1. pwd command: display the current directory (e.g., /home/george) 2. ls command: list the files in your current location You’ll likely not see any files listed when you first try ls. That doesn’t mean there aren’t any files. It just means that you’ll have to work a little harder to see them. The ls command assumes that you don’t want to see files that start with dots and any files that are included in a new home directory, like .bashrc, start with dots. Use the ls -a command and, voila, you’ll see some files. 3. cat command: display file contents of a text file To view the content of a .bashrc file or any text file for that matter, you can use the cat command. No, this has nothing to do with our feline friends. This cat stands for “concatenate”, but that’s a story for some other chapter of your Linux voyage. 4. more command: display a text file one screenful at a time 5. less command: display a text file one screenful at a time and allow backing up If you’re trying to display a text file that has lots of lines, the cat command will display the file as the lines rapidly move up your terminal window. If you want to view these files in a screenful-at-a-time manner, use the more or the less command. These commands are very similar, but less lets you back up if you want using the up arrow key. 6. cd command: move into a particular directory or back to your home To move to another directory, use the cd command. For example, you can move into the /tmp directory with the command cd /tmp. Moving back to your home directory is even easier. Just type cd by itself and you’ll move right back to your home directory. 7. touch command: create blank/empty files To create a new file, you can use the touch command. This command (e.g., touch newfile) creates an empty file but, hey, you’ll have more files to list. 8. echo command: display the specified text If you want to add a little content to your new file, you can use the echo command and redirect the output into a file with a command like echo “read me” > newfile. If you run that same command again, the file will not change. That’s because the single > in the command will cause the echo command to overwrite any prior content. If you want to add a line to an existing file, use >> instead. 9. rm command: delete a file If you want to delete a file, you would use the rm command (e.g., rm myfile). As you might suspect, you can only remove files that you own. So, this is a good point to try another ls command – ls -l. This command will not just list your files, but will display them with lots of extra details as in this example: -rw-r--r--. 1 george george 8 Nov 6 13:28 newfile “What’s all that about?” you ask. The initial – means that we’re looking at a regular file. In other words, it’s not a directory or a file that points to another file. The rw- part means that you (george in this example) have read and write access to the file. If anyone else is a member of the george group (yes, the group would exist), they would have read access only (the following r–). Note that it is almost never the case for user groups like george to have more than a single member. The final r– would give read permission to anyone else who logs into the system if they had access to your home directory which is almost never the case. In general, only the owner of an account and the all powerful root account can mess with your files. 10. mv command: rename a file To rename a file, use the mv command (e.g., mv newfile oldfile). Note that, if you include a full path, you can not just rename a file, but you can move it to some other location provided you have write permission to that directory. To move your file into the /tmp directory, which anyone can use, use a command like this: mv newfile /tmp If you want to move a file and rename it at the same time, you can use a command like this: mv newfile /tmp/oldfile 11. cp command: copy a file To copy a file, use the cp command (e.g., cp thisfile thatfile). You can copy a file to another directory by using a full path (e.g., cp myfile /tmp/yourfile). 12. passwd command: change your password If you need to change your password, use the passwd command. You’ll be prompted to enter your current password and then to enter the new password twice. Just don’t be surprised if it doesn’t work the first time. Linux systems tend to be fussy about passwords. They generally want them to be so many letters long and not based on common words. Make sure that you’ll be able to remember the password you end up choosing or you’ll likely need the assistance of someone with access to that powerful root account to reset it for you. After logging in and examining files, what’s next? Once you get comfortable with logging into a Linux system and examining the files in your account, it’s time to try out some additional commands. 13. clear command: empty the terminal screen One of the commands you should try right away is the clear command. It clears your terminal window. This can be useful when you want to look at the output of some command without being distracted by whatever is being displayed when you start. 14. head command: display top lines in a text file 15. tail command: display bottom lines in a text file You can use the head and tail commands to view the top and bottom lines of a text file. Each of these commands will display 10 lines by default. Type a command like “head .bashrc” and you’ll see the first 10 lines while “tail .bashrc” will display the last 10. To view only the bottom two commands in a file, you can use a command like this: $ tail -2 .bashrcalias byebye='echo "Have a happy and very profitable day!"; exit'alias c=clear Note that the byebye alias shown above would both issue a wish for a good day and then exit the terminal window or the system (if you’re logged in remotely). The semicolon separates the commands while allowing them to be run from a single line. 16. man command: provide a description of what a command does Another command to start using right away is the man command. That “man” stands for “manual”. In other words, it provides instructions on whatever command you’re asking about. For example, typing “man pwd” will provide a description of what the pwd command does along with details on all of the command’s options. 17. date command: view the current date and time To view the current date and time, use the date command. You’ll see the details in output that is formatted like what you see below: $ dateSun Nov 10 01:32:00 PM EST 2024 18. cal command: view a calendar for the current month To view a calendar for the current month, use the cal command. To view a calendar for some other month, add the month and year like this: $ cal 03 1949 March 1949Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 1213 14 15 16 17 18 1920 21 22 23 24 25 2627 28 29 30 31 19. whoami command: display the username for the account you’re using The whoami command will display the username associated with the account you are using. This is normally so obvious that you’d never need to ask but, if you switch accounts and want to be reminded which you’re using right now, this command can be helpful. 20. alias command: set up short names for often used commands Once you start using more complex commands, you might consider using the alias command to set up short names for commands that you use frequently. For example, if you want to clear your screen by typing a single “c”, you can set up an alias to make this possible. The alias would look like this: $ alias c=clear The only complication is that, if you want this alias to be available every time you log in, you’ll need to add it to your .bashrc file. You could do that with a command like this: $ echo “alias c=clear” >> .bashrc Be very careful to use >> and not >. Using only > would overwrite the file while >> adds to it. 21. history command: view recent commands To view the commands that you’ve run recently, use the history command. The most recent commands you’ve run will be displayed last, but your list is likely to include as many as the last 1,000 commands that you’ve run. To check how many commands will be displayed, you can use the command shown below to display the setting. $ echo $HISTSIZE1000 22. grep command: look for a certain word or string in a text file If you want to look for a certain word or string (a group of words) in a text file, you can use a grep command like that shown below that looks for command aliases in your .bashrc file. $ grep alias ~/.bashrc The ~/ in that command means this command will look in your .bashrc file even when you’re not sitting in your home directory when you run it. The ~ means your home directory (e.g., /home/username). To view all the directories that might be checked when you run a command, use the “echo $PATH” command. The first matching command will be the one that is run. To determine the location of the command that will be run, you can use a command like that shown below. $ which date/usr/bin/date 23. sort command: sort the contents of a text file If you want to sort the contents of a text file, use the sort command as in the example below. $ sort friendsAliceBettyChristopherDianeGeorgePattyRickySamTim 24. mkdir command: create a new directory To create a new directory in your home directory (i.e., a subdirectory), use the mkdir command as in the example below. $ mkdir reports Once you create a new subdirectory, you can move into it with the cd command. 25. ps command: view running processes To view the processes you are running, use the ps command with no arguments. In the example below, the only two processes being run are the bash shell and the ps command itself. $ ps PID TTY TIME CMD 64681 pts/1 00:00:00 bash 68330 pts/1 00:00:00 ps To view all of the processes that are running on the system, use one of the ps commands shown below. The correct command often depends on what Linux distribution you are using. $ ps -ef$ ps -aux To view running processes one screen at a time, you can use what is called a “pipe” – a special command option that allows you to send the output of one command to another command. Here’s the command that would do this for you: $ ps -ef | more In the command above, the output of the ps -ef command is sent to the more command which displays that output one screenful at a time. Wrap-up Well, that’s a start. If you’re intrigued by this introduction to the Linux command line, please try out some of the commands and be on the lookout for more Linux tips and tricks. SUBSCRIBE TO OUR NEWSLETTER From our editors straight to your inbox Get started by entering your email address below. Please enter a valid email address Subscribe