02 Linux - Fundamentals
02 Linux - Fundamentals
Contents
What is a Shell?
Shell commands
Why to use CLI over GUI?
● Less resources ( graphics components add to more required memory )
● High precision
● Repeatative tasks friendly
● Powerful
But always remember.......
echo $SHELL
How to check what a particular command do?
● man <command>
● e.g. man ls
How to check the list of files in a folder?
● ls -a <folder> (all)Lists all the files (including .*files)
● ls -l <folder> (long) Long listing (type, date, size,owner, permissions)
● ls -t <folder> (time) Lists the most recent files first
● ls -S <folder> (size) Lists the biggest files first
● ls -r <folder> (reverse) Reverses the sort order
● ls -ltr <folder> (options can be combined) Long listing, most recent files at the end
File name pattern substitutions
ls *txt
The shell first replaces *txt by all the file and directory names ending by txt (including .txt), except
those starting with ., and then executes the ls command line. This will work when you are
inside the directory.
ls -d .*
Lists all the files and directories starting with “.” and d tells ls not to display the contents of
directories.
Thats great that it worked but what was . And .. ?
cat ?.log
Displays all the files which names start by 1 character and end by .log
Working with directories
command function
pwd print working directory
mkdir dirName make directory
mkdir -p dirName create parent directory
rmdir dirName remove directory
rm -r dirName or rm -ri dirName or rm -rf dirName remove dir recursively (add f for force), -i with permission
cd /dirName/dirPath go to a specific dir
cd takes you to home directory
cd ~ home directory
cd .. previous directory
cd - previous dir with path
Practice: working with directories
● Display your current directory. ● Stay where you are, and list the contents of
● Change to the /etc directory. ~.
● Now change to your home directory using ● List all the files (including hidden files) in your
only three key presses. home directory.
● Change to the /boot/grub directory using only ● List the files in /boot in a human readable
eleven key presses. format.
● Go to the parent directory of the current ● Create a directory testdir in your home
directory. directory.
● Go to the root directory. ● Change to the /etc directory, stay here and
● List the contents of the root directory. create a directory newdir in your home
● List a long listing of the root directory. directory.
● Stay where you are, and list the contents of ● Create in one command the directories
/etc. ~/dir1/dir2/dir3 (dir3 is a subdirectory from
dir2, and dir2 is a subdirectory from dir1 ).
● Stay where you are, and list the contents of
/bin and /sbin. ● Remove the directory testdir.
Working with files
“Everything in Linux is a file, Everything in Linux that is not a file is a process”
Let’s learn how to recognise, create, remove, copy and move files using commands:
command function
mv fileName1 fileName2 or mv fileName1 filePath/dirPath move file content or file to other dir
cat > fileName create file with concatenated content (ctrl+d for EOL)
File, Users, Groups and Permissions
Users, Groups and Permissions
● Use ls -l to check file access rights
● 3 types of access rights
● Read access (r)
● Write access (w)
● Execute rights (x)
● 3 types of access levels
● User (u): for the owner of the file
● Group (g): each file also has a “group” attribute, corresponding to a given list of users
● Others (o): for all other users
Changing permissions
chmod <permissions> <files>
1. Numerical values
e.g.
grep pattern fileName searches a file or files for lines that have a certain pattern
| pipe Pipes '|' send the output of one command as input of another command.
kill <pids> Sends an abort signal to the given processes. Lets processes save data and exit by themselves
df -h Returns disk usage and free space for the filesystem containing the given directory.