Linux Chuck
Linux Chuck
• There are more distributions of Linux like (Kali Linux, ubuntu) use a certain
version of the Linux kernel.
• Linux is not an OS it's a kernel and we build OS on top of it (it interfaces with the
hardware) (Open source, faster and more secure)
pwd >> Print Working directory (tells you where you at)
ls >> stands for list (or ll)
cd >> change directory
cd .. >> back to the previous (you can keep using it until reaching "/" the root of the
file system) (the end)
cd ../.. >> go back twice.
whoami >> what I'm logged in as
clear or ctrl+l >> will clear your terminal.
cd / >> going to rood directly.
cd >> go home directly.
cd - >> go to the previous directory (basically by checking the $OLDPWD flag)
>> You can show it using “echo $OLDPWD”
ls -al >> list & show hidden files (or al)
exit or ctrl+d >> exit a specific mode.
ctrl+(+) ctrl+(-) >> zoom in & out
ctrl+a & ctrl+e >> Go to the beginning and end of the command line.
ctrl+u >> delete everything before my cursor.
ctrl+k >> delete everything after my cursor.
ctrl+y >> paste (cosidering the above as cut)
• You can use the "less" command instead of "cat" for large file.
• "cat" takes much time as it loads the whole file but "less" loads just a part of it.
tail /var/ >> double-tab here will display available directories inside var to continue the
command.
mkdir >> create directory.
tree >> command: give us a cool output of our directories.
touch >> to create files (touch file.txt)
rm >> remove file.
rmdir >> remove directory.
rm -r >> remove everything inside of a directory and the directory itself.
cat << EOF > file.txt (when we type EOF and enter it will be the end of it)
>whatever
>whatever
>whatever
>EOF
• another way of fast file creation: echo "file body whatever" > file.txt
• "cp" is just like "mv" but it keeps the original file in its place and copies it
copy a file to another file in the same directory (for backup): cp file.txt file2.txt
• directories can be moved and copied just like the files (if you want to copy a
directory and copy everything inside it as well you have to use "cp -r" “recursive”)
• The directory [bin] on the root stands for binary and it contains command binary
(the commands itself is a file)
• The directory [sbin] (super bin) >> special commands for demonstrators
adduser >> (adding a new user) example:
(sudo adduser malnadi) >> will be created in the [home] directory.
The directory [usr] will have the [bin] & [sbin] directories which are the same as the ones
in the root directory, it also has the [local] directory in which you can store the
commands that you create.
which >> where your binary command is (which ls) >> will show you the location
• To check the root content: (sudo ls root)
sudo adduser thor >> add a user (when you create a user in Linux you create a user and
a group for that user as well)
sudo useradd ironman >> (lazy command create a user rightaway)
• Then we can set a password as below (this command can also change the
password for any username: sudo passwd ironman
• using this command also (user won't exist in home directory) and will have a (sh)
instead of (bash) next to it; can be changed using the below command:
• you won't be able to use the sudo command with one of the newly created users
(no permissions)
• The only recommended way to edit the sudoers file is through the command:
sudo visudo
%sudo >> Any user part of this group can use any command they want
Allowing all users within a group to do whatever without a need for a password:
if there's a syntax error after trying to save the file the system will indicate that and give
you some options
(-G only will add a user to a group and eliminate other groups so the small a is to
(append) the groups that Ironman is part of)
• download something from the browser as a .dep format which is the format for
packages in linux (in depian based system) then sudo dpkg -i discord-0.0.43.deb
• (apt) advanced package tool (only needs the package name and doesn't require
downloading of the .dep file), apt relies on a repository (storage location)
(collection of software)
sudo apt -h >> will tell us all the stuff that we can use, example:
sudo apt update >> go to the repository and request a list of everything there
sudo apt install pidgin
pidgin
snapd (apps can be added to snap store and be available for fast access), example:
sudo apt install snapd
sudo snap install --classic code
code
To show where our repository is stored: sudo apt edit-sources
>> can copy the path and then type it after a (sudo nano) command to show it.
• You can pull down stuff from GitHub for example and install it by copying the link
and then git clone (that link), we might need some requirements that will show in
a Txt file inside of the installed and we can do the following:
daemon >> a process that we don't start (it will have a "d" on the end of the process
name) (networking, printing, ssh)
for example: ps -aux | grep ssh >> will show (sshd) process
master daemon >> Systemd (service manager, initialixation of the system "init"
boot >> kernel >> systemd (mounting file system, starting services)
You can check its status (next to the Active field) using the command:
sudo systemctl status sshd
Other commands:
Restart the service: sudo systemctl restart sshd
reload and if can't reload restart: sudo systemctl reload-or-restart sshd
Auto startup for daemons:
Turn off auto startup for a daemon: sudo systemctl disable ntp
You will confirm that in the field of (Loaded) using the command:
sudo systemctl status ntp
sudo systemctl enable ntp >> The daemon will be enabled on the next boot
Linux Processes
• You can issue a sleep for defined seconds (sleep 30) and then you can't do
anything until using for example ctrl+c, ctrl+c can be also used when there's an
ongoing job that needs to be stopped, for example, ping -c 100 google.com, so
ctrl+c is a form of (kill).
• You can use ctrl+z to stop the job instead of killing it with ctrl+c
• Stopped jobs can be shown using (jobs) and can be resumed using bg if we have
more than job we can stop it by mentioning the job ID
• to bring it back to foreground (fg 1) we need to specify the ID and then we can kill
or stop it again.
• You can use & to put the job in the background immediately like (sleep 900 &).
kill -l >> will show us all the signals that can be sent.
signal number 9 (SIGKILL) this force killing of the process no matter what.
You can use a specific kill signal but you got to know the job ID:
------------------
pgrep sleep
7036
kill -19 7036
------------------
The equivalent kill signal of ctrl+c is the number 2: kill -2 7036, the ultimate kill
command: kill -9 7036
kill all processes at the same time: use pkill command like this (specifying job name):
pkill -9 ping >> kill all ping processes.
Summoning a Web server to manage our file in linux (similar to FTP and others):
python -m http.server 7600
then on the browser: localhost:7600 >> this will launch the current directory
(localhost translates to the loop back IP address 127.0.0.1)
curl command "client URL" >> many uses like downloading files
curl localhost:7600 (you will download the sourcecode for the website)
curl -o coolwebsite localhost:7600 (will download it to a file called "coolwebsite")