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
download a file given a link
wget download-link
check linux system information such as machine name, operatin system, kernel
uname
cat /proc/cpuinfo
task manager but for linux
top
see a list of previous commands run
history
get a list/help with linux commands
man
check ip address
ip addr
hostname -i
how to copy a file, directories, while preserving file state?
cp file1 file2 – copies file1 to file2
cp file1 file2 new – copies file1/file2 into new dir
cp -R dir1 dir2 – copies all files from dir1 into dir2. If dir2 exists it will make a subdir of dir1 in dir2, if it does not exist it will create dir2
-p option preserves all information about the file, time of last edit, permissions, ect
monitor a process on the system
ps aux | grep
do 2 tasks at once in a single line
use &&
cd /home && ls - al
cd’s to home and executes ls -al