8 September 2021 | get inspired | , | 0 Comments

UNIX commands cheatsheet

Unix was released in October 1973. Today there are many different versions based on Unix. The most prominent are GNU/Linux and MacOS. 90% of all cloud infrastructure is powered by Linux and 74% of smartphones in the world are Linux-based.
If you want to see whats going on an EC2 instance or filter some log files you can always use the command line tools.

Using the command line tools for administrative work or lookups will save a lot of time and increase the productivity significantly compared to using only graphical interfaces.

As a web developer we use the following commands on a daily basis. If you are new to this topic, I hope this will help you increase productivity.

Orientation

commandexplanation
historydisplays the history of the last used commands
pwdprint working directory
man [command]manual
echoechoes an argument

Navigating in the terminal

When we keep our hands on the keyboard we are always faster, than when use the mouse or similar to navigate around. So we should make use of the following commands, when we are in a terminal.

ctrl + a: jump to the beginning of a line
ctrl + e: jump to the end of a line
ctrl + w: remove word
ctrl + c: remove whole line
option + left arrow: jump to the end of a word
option + right arrow: jump to the beginning of a word
tab: autocompletion
arrow up: show last used command
cmd + k: clear terminal screen

Navigating in the file system

commandexplanation
lslist – lists all files in the current directory
ls -alists all but also shows the .hidden files
ls -lalists all files in the long file format
cd /navigate to the root directory
cd ~navigate to the home directory
cd ..navigate one directory level up
cd –navigate to the previous directory

Administrative tasks

commandexplanation
sudosuperuser do
mkdir [directory_name]make directory
rmdirremoves a directory
touch [file_name]creates a file
cp old_file_name new_file_namecopy
mv old_file_name new_file_namemove
rm [file_name]remove
rm -rremoves recursive, ie a Folder with all contents
vi [file_name]opens file with vi
nano [file_name]opens file with nano
code [file_name]opens file with vs code
program_nameto start a program simply type the name, ie python
ctrl + cstop a program

Searching and filtering

commandexplanation
head [file_name]show the first 10 lines of a file
tail [file_name]show the las 10 lines of a file
sort [file_name]sorts the file alphabetically
sort [unsorted_file_name] > [sorted_file_name]sorts the content of the unsorted file and stores it in a new sorted file
cat [options] [file_names]reads files sequentially, writing them to standard output
grep [options] pattern [file_names]globally search for regular expression and print
the pipeThe pipe send the output of one command as input of another command.

As grepcat and | are powerful tools I recommend having a look at this awesome tutorial.

Permissions

In Unix Systems there are three groups of ownership.

  • USER: the one who created the file
  • GROUP: a group with assigned users
  • OTHER: any other who has not created the file and does not belong to a group.

The UNIX system has 3 permissions defined for the 3 different owner groups:

r = read permission
w = write permission
x = execute permission

– = no permission
d = directory
@ = extended attributes on macOS

Changing permissions

commandexplanation
chmodchange mode
chownchange owner

Detailed information for the permission system can be found here.

This post is outlining the most important commands (for me). If you want to see all commands you might want to have a look at this list or use the man in the terminal.

Source: dev.toAuthor: Barbara (dev)

Leave a Reply

Your email address will not be published.

Scroll to top