Linux Commands
List Directory (ls)
ls /
Shows all directories, defaults to current level
ls -l /
– Long flag, shows file permissions. File owner, file size and timestamp for last time edited
Manual page
man ls/
Install with:
apt install coreutils
Print Working directory (pwd)
pwd
– shows current directory
Change Directory (cd)
cd ../home
– go to home directory – relative syntax
cd /home
– go to home directory – absolute syntax
cd ~/
– go back to root
Make New Directory (mkdir)
mkdir dir_name
– makes a directory called “dir_name”
mkdir dir1 dir2 dir3
– makes 3 directories
Remove Directory (rmdir)
rmdir dir_name
– deletes directory
rmdir dir1 dir2 dir3 dir4
– removes list of directories
Make a File (touch)
touch empty_file
– makes a file?
Copy Files (cp)
cp my_cool_file.txt ~/
– this command copies the file to the root folder
Move Files (mv)
mv .apple .banana .broccoli .milk /home/user/Documents/Hidden
– moves multiple files, same name
mv /home/user/source_file /home/user/moved_files/target_file
– moves and renames file
Delete Files (rm)
rm /home/user/duplicates/target_file
– deletes target_file
Flags – Add flags to change Functionality
–help – display help for command
-r – recursive, means every action executed on the parent will be done unto the child
Find Files (grep)
grep -rw /home/user/Downloads -e "vacation"
– searches for files with the word vacation in them
Options and flags (grep)
- -r: search recursively
- -w: match the whole word
- -n: only in line number
- -e: match pattern
- –include and –exclude: include and exclude files in the search
- –include-dir and –exclude-dir: include or exclude directories in the search
Change Permissions (chmod)
sudo chmod u+x secret_folder/
– “u” stands for “user” and “x” stands for “execute”
sudo chmod g+w secret_folder/
– give the group write permissions
sudo chmod g-r secret_folder/
– take away read permissions from the group
sudo chmod o-r secret_folder/
– remove read permissions for everyone
ls -ld secret_folder/
– check permissions
Change Owner – (chown)
sudo chown cook /home/qwiklab/taco
– make cook the owner of the file taco
Installation Example (Atom)
sudo dpkg -i /home/qwiklab/downloads/atom-amd64.deb
– installs local Debian file
sudo apt install -f
- installs dependencies for prev
dpkg -s atom - verify install
Installation Example (7-zip)
sudo apt install p7zip-full
– installs 7-zip, re-run the command to verify
Uninstalling Example (GIMP)
sudo apt remove gimp
dpkg -s gimp
Extracting an Archive
cd /home/qwiklab/downloads
-change into the directory first!
sudo tar -xvf extract_me.tar
– extracting the file
Archiving files
cd ~ – change into root
tar -cvf Planets.tar --absolute-names /home/qwiklab/documents/Earth /home/qwiklab/documents/Mercury /home/qwiklab/documents/Venus
- Targets multiple files with absolute paths originating from root
Blocks and Partitions
Blocks – Blocks are a layer of storage devices that allow individual access to each independently. They allow programs to access storage without worrying about whether the underlying hardware device is a hard drive, solid state drive, flash drive, etc.
Partitioning
Lsblk
– view the devices attached to your machine
df -h
– view disks mounted on the system, -h flag displays human readable format
sudo fdisk -l
– list all partitions
sudo fdisk -l /dev/sdb
– start fdisk utility, h = help, n = new part, d = delete, v = verify, w = commit
Formatting
lsblk
– view the devices attached to your machine
sudo mkfs -t ext4 /dev/[SECOND DRIVE]2
sudo mount /dev/[SECOND DRIVE]2 /home/my_drive
lsblk
Terminating Processes
ps -aux | grep "totally_not_malicious"
– Find processes based on the name
sudo kill [PROCESS ID]
– Find process and kill it
ps -aux | grep "totally_not_malicious"
– Confirm kill
Leave a Reply