Linux command line must-have!


Working with the command line is fun! Change my mind ;) But you need to know few basic commands first. Checkout absolute must-have...

Foreword

Like I stated in the excerpt - working with the command line is fun. But there is no fun without basics. For better readability, I organized commands into logical areas. I will try to add new commands - so please came back from time to time.

I will try to describe commands in such an order that you will be able to execute them one after the other. Command explanations and additional info will be in the comments.

This tutorial is mostly dedicated to beginners. It is why I must explain few things:

  • Comments are from # till the end of a line; Please do not execute them.
  • Directory and folder mean the same. A folder is a language construct forced by Microsoft.

Some of the commands are quite risky! Please double-check typing before execution. You have been warned - I don't take responsibility for any damages!

OK - let's start typing commands :)

File system operations

# change directory to the defined one - in this case /var
cd /var

# change directory to the current user's home (on many terminals `~` will show up after next key pressed - do not worry keep typing)
cd ~

# change directory to root one
cd /

# create 'webee' in your home directory:
mkdir ~/webee

# list directory content with details (you should see now 'webee' on the list)
ls -la ~

# create 'school' sub-directory of 'webee' directory
mkdir ~/webee/school

# show directory you are currently in
pwd

# create a new empty file in ~/webee/school directory
touch ~/webee/school/first_file.txt

# delete a single file
rm ~/webee/school/first_file.txt

# create a file and insert content into it
echo 'This is file content' > ~/webee/school/second_file.txt

# display file content
cat ~/webee/school/second_file.txt

# delete folder with all data in it (folders, sub-folders, files - everything inside)
rm -r ~/webee

# create 'webee' and 'school' at the same time
mkdir -p ~/webee/school

# create a directory and go to it in a single command
mkdir ~/webee/online && cd $_

# create many folders at once, will create:
# ~/webee/online/page/main
# ~/webee/online/page/list
# ~/webee/online/page/category
mkdir -p "page/{main|list|category}"

# remove webee without asking and go back into the home directory - try to not delete the branch you are sitting on
rm -rf ~/webee && cd ~

# check disk space statistics
df

Warning: NEVER DO THIS: rm- rf /

System-related

# show logged-in users
w

# show username of currently logged in user
whoami

# show list of all processes with details
ps -el

Package manager

Like usually for Debian only ;). sudo allows to call a command with elevated permissions - usually root users permissions.

# update packages repository
sudo apt-get update

# upgrade packages to the newest versions - call after update
sudo apt-get upgrade

# install package e.g. vim
sudo apt-get install vim

# install many packages at once
sudo apt-get install gzip tar

Files and directories permissions

Before we start some preparations are needed:

# add a new user named 'webee'
adduser -mU webee

# create directories to play with
mkdir -p ~/webee/"{online|school}/page/{mian|list|category}"

# create a new file
touch ~/webee/test_file.txt

Now you are ready to play:

# set both owner and group of 'webee/online/page' directory only (without sub-directories)
chown webee:webee ~/webee/online/page

# set both owner and group for 'webee/school/page' directory and all of its children
chown -R webee:webee ~/webee/school/page

# set permissions to 777 (rwxrwxrwx) on `test_file.txt`
chmod 777 ~/webee/test_file.txt

#set permissions to 664 (rw-rw-r--) on 'webee' directory including all children
chmod -R 664 ~/webee

Type safely and logout!

Not enough?


Would you like me to build and conduct training tailored to your needs? I'm waiting for your call or message.

address icon

WeBee.Online Adam Wojciechowski
ul. Władysława Łokietka 5/2
70-256 Szczecin, Poland