Linux terminal commands

17 2 0
                                    

I found a very good list of the most common Linux terminal commands. It's from the official Raspberry Pi website and even though the list is meant for mainly Raspberry Pi users all commands displayed here work on any Linux based computer (or subsystem for Windows)

Source: https://www.raspberrypi.org/documentation/linux/usage/commands.md


Filesystem

ls

The ls command lists the content of the current directory (or one that is specified). It can be used with the -l flag to display additional information (permissions, owner, group, size, date and timestamp of last edit) about each file and directory in a list format. The -a flag allows you to view files beginning with . (i.e. dotfiles).

cd

Using cd changes the current directory to the one specified. You can use relative (i.e. cd directoryA) or absolute (i.e. cd /home/pi/directoryA) paths.

pwd

The pwd command displays the name of the present working directory: on a Raspberry Pi, entering pwd will output something like /home/pi.

mkdir

You can use mkdir to create a new directory, e.g. mkdir newDir would create the directory newDir in the present working directory.

rmdir

To remove empty directories, use rmdir. So, for example, rmdir oldDir will remove the directory oldDir only if it is empty.

rm

The command rmremoves the specified file (or recursively from a directory when used with -r). Be careful with this command: files deleted in this way are mostly gone for good!

cp

Using cp makes a copy of a file and places it at the specified location (this is similar to copying and pasting). For example, cp ~/fileA /home/otherUser/ would copy the file fileA from your home directory to that of the user otherUser (assuming you have permission to copy it there). This command can either take FILE FILE (cp fileA fileB), FILE DIR (cp fileA /directoryB/) or -r DIR DIR (which recursively copies the contents of directories) as arguments.

mv

The mv command moves a file and places it at the specified location (so where cp performs a 'copy-paste', mv performs a 'cut-paste'). The usage is similar to cp. So mv ~/fileA /home/otherUser/ would move the file fileA from your home directory to that of the user otherUser. This command can either take FILE FILE (mv fileA fileB), FILE DIR (mv fileA /directoryB/) or DIR DIR (mv /directoryB /directoryC) as arguments. This command is also useful as a method to rename files and directories after they've been created.

touch

The command touch sets the last modified time-stamp of the specified file(s) or creates it if it does not already exist.

cat

You can use cat to list the contents of file(s), e.g. cat thisFile will display the contents of thisFile. Can be used to list the contents of multiple files, i.e. cat *.txt will list the contents of all .txt files in the current directory.

head

The head command displays the beginning of a file. Can be used with -n to specify the number of lines to show (by default ten), or with -c to specify the number of bytes.

tail

The opposite of head, tail displays the end of a file. The starting point in the file can be specified either through -b for 512 byte blocks, -c for bytes, or -n for number of lines.

You've reached the end of published parts.

⏰ Last updated: Jan 22, 2021 ⏰

Add this story to your Library to get notified about new parts!

Random computer tricksWhere stories live. Discover now