This content originally appeared on DEV Community and was authored by Barbara
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 webdeveloper 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
command | explanation |
---|---|
history | displays the history of the last used commands |
pwd | print working directory |
man [command] | manual |
echo | echoes 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
command | explanation |
---|---|
ls | list - lists all files in the current directory |
ls -a | lists all but also shows the .hidden files |
ls -la | lists 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
command | explanation |
---|---|
sudo | superuser do |
mkdir [directory_name] | make directory |
rmdir | removes a directory |
touch [file_name] | creates a file |
cp old_file_name new_file_name | copy |
mv old_file_name new_file_name | move |
rm [file_name] | remove |
rm -r | removes recursive, ie a Folder with all contents |
vi [file_name] | opens file with vi |
wq | write and quit |
wq! | write and quit forced |
nano [file_name] | opens file with nano |
code [file_name] | opens file with vs code |
program_name | to start a program simply type the name, ie python |
ctrl + c | stop a program |
Searching and filtering
command | explanation |
---|---|
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 pipe | The pipe send the output of one command as input of another command. |
As grep
, cat
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
command | explanation |
---|---|
chmod | change mode |
chown | change 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.
This content originally appeared on DEV Community and was authored by Barbara
Barbara | Sciencx (2021-09-03T12:19:20+00:00) UNIX commands cheatsheet. Retrieved from https://www.scien.cx/2021/09/03/unix-commands-cheatsheet/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.