Comprehensive Linux Command line
Common Linux Distros:
- Ubuntu
- Debian
- alpine
- Fedora
- CentOS
Ubuntu Linux commands
Linux uses / slash between files and folders (vs windows which uses \). Also, Linux is case sensitive OS
echo hello
hello
whoami
root
echo $0
/bin/bash(location of the shell program)
Echo $0
command not found
history
list all the commands we have used lately
!2
This will execute the second command from the history list
Package manager for ubuntu (apt)
with nano- basic text editor for linux
apt update
updates the packages db
apt list
list all the packages
apt install nano
installs nano
nano
opens nano
apt remove nano
removes nano
Linux file system
/
root dir
/bin
includes binaries or porgrams
/boot
includes all the files related to booting
/dev
short for devices and files that are needed to access devices are present here
/etc
for configuration file
/home
for user files. so on a machine with multiple users each user will have a home directory here
/root
home dir of the root user
/lib
for libraries file like software library dependency
/var
short for variable here we have files that are updated frequently like log files
/proc
includes files that represent running processes
Navigate Linux file system
pwd
print working dir
ls
list contents
ls -1
list one items per line
ls -l
list more details
cd
change current directory
cd ..
go one level up
cd ../..
go 2 level up
ls /bin
list content of bin directory with absolute path
ls bin
list content of bin directory with relative path
cd ~
takes you to the home directory of the user
Manipulate file and directories
mkdir test
makes a new dir test
mv test docker
rename dir test to docker
touch hello.txt
creates a new text file hello
touch hello.txt hello1.txt hello2.txt
creates a multiple text files
mv hello.txt hello-docker.txt
renames the file
mv hello-docker.txt /etc
moves the file to the /etc folder
rm hello1.txt
remove the file
rm hello*
removes all files starting with hello
rm -r docker/
removes the docker directory recursively
Edit and view files
cat file1.txt
shows the content of the file
cat file.txt file2.txt
shows the content of both files
more file.txt
use for big files (use space to see next page and enter to see line to line, we can only view the file downwards)
less file.txt
use up and down arrow to view the file along with space and enter
head -n 5 file.txt
shows the first five lines
tail -n file.txt
show last five lines
Standard input and output
cat file.txt > file2.txt
will read the content from file1.txt and write it to file2.txt