Linux Flashcards
Check memory usage
free -h shows all free memory
du -h -d 1 (disk usage, human, depth =1) meaning the depth of folders it will look.
df -h shows how much memory each directory is consuming in human readable form
Du -a -h -d 1 shows you all the files, hidden files, and directories disk usage
Find text in a directory
grep /path/to/file -e text-to-search
grep /path/to/dir -e text-to-search
grep -rnw /path/to/dir -e text-to-search
- r or -R is recursive,
- n is line number, and
- w stands for match the whole word.
- l (lower-case L) can be added to just give the file name of matching files.
- e is the pattern used during the search
Read file to console
cat
Open file to edit
vim
In vim
quit file, save quit, edit file, how to stop editing
:q!, :q, :wq, [i] for insert, escape to stop editing
print files in dir
ls, ls -al shows all hidden files with permissions
move file, make directory, remove directory, make file
mv file1 file2
mkdir dirName
rmdir dirName
touch file
find a file
find /dir/ -name file.txt
searches for the file in the dir and sub dirs
read beginning or end of files
head -n file.txt
tail -n file.txt
See differences between 2 files
diff file1 file2
remove file, remove directory, remove directory and all sub files/dirs
rm file, rmdir dirname, rm -rf dirname
create a tar file, unzip a tar file
tar -cvf name.tar dirname/or/filename
- c create tar
- v verbose
- f specify file name
tar -xzf tar.gz
- x extract
- z gzip, gunzip, ungzip,
- f file
change read-write permissions, change owner
chmod filename
chown newowner:newgroup filename
show all jobs running and their statuses. Jobs are started by the shell
jobs
stop a process
kill -9/-15 PID