Useful terminal commands for devs
Being practical is a one way ticket.
I always preferred using terminal over GUI apps to control my projects or to navigate through folders on my disk. I admit this is not really the most intuitive and friendly approach but one thing is for sure: once you get used to this you’ll want to use terminal for pretty much anything possible.
Touch
The touch command creates new, empty files. It is also used to change the timestamps (i.e., dates and times of the most recent access and modification) on existing files and directories.
touch empty_file.txt
Mkdir
The mkdir command allows the user to create directories (also referred to as folders in some operating systems ).
mkdir my_folder
Ls
The ls command is used to list files or directories. By using -a argument all the files including hidden ones get listed. When using -lh argument its possible to see also the permissions of the file and owners.
ls -a -lh
Pwd
The pwd command prints the name of the current working directory.
pwd
Cp
The cp command stands for copy and — wait for it — is used to copy files or group of files or directory.
cp file.txt other_file.txt
Rm
The rm command stands for remove. It removes files but, in case we want to remove a folder and its content we need to use -r argument which means recursively. You can also use ‘*’ when referring to everything in the current working directory.
rm any_file.txt
rm -r photos
Cd
The cd command stands for change directory. It is used to change the current working directory and can be used by passing either the path forward or ‘..’ to navigate back or even simply ‘cd’ to navigate to root.
cd path/to/something
Clear
The clear command cleans the current displayed output on the terminal.
clear
Sudo
The sudo command allows you to run programs with the security privileges of another user (by default, as the superuser).
sudo open some_file.txt
Chown
The chown command is used to change the owner of file system objects (files and directories). The name is an abbreviation of change owner.
chown root file.txt
Chmod
The chmod command is used to change the access permissions of file system objects (files and directories). The name is an abbreviation of change mode. The permissions can look something like this: -rwx rwx rwx. r=read, w=write, x=execute. If there’s a dash it means there’s no permission. The first three on the left refers to permissions for the current user. The three in the middle refers to the user group and the last three to others.
chmod 600 file.txt
600 will result on a permission of read and write for the current user, no permission for execution for this same user and nothing to anyone else. 6 is 110 in binary, which means (1)true (1)true (0)false = rw-
Let’s say we wanted full permission for everyone — we would use the number 777 because in binary that’s 111 111 111 = rwx rwx rwx
Cat
The cat (short for “concatenate“) command allows us to concatenate files and redirect output in terminal or files.
cat name_list.txt
Grep
The grep command is one of my favourites. Its used to search for a string on a file. It goes very well along with the next commands.
grep Bruno
Pipe
The pipe command (which is simply ‘|’) helps you mix two or more commands at the same time and run them consecutively.
cat name_list.txt | grep Bruno
Tail
The tail command prints the last few number of lines (10 lines by default) of a certain file, then terminates. When using -n argument its possible to define the exact amount of lines to be printed. The -f argument causes tail to not stop when the end of the file is reached, but rather waits for additional data to be appended to the input.
tail -n 5 -f
Man
The man command is used to display the user manual of any command that we can run on the terminal. It shows all the arguments that can be passed to a command.
man tail
man grep
Special thanks to Richard Carback and Ben Wenger for introducing me to some of those commands.