Skip to content

Instantly share code, notes, and snippets.

@aneesh-joshi
Last active February 16, 2019 00:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aneesh-joshi/6ce022e915e53cd558250b85ebbde5cb to your computer and use it in GitHub Desktop.
Save aneesh-joshi/6ce022e915e53cd558250b85ebbde5cb to your computer and use it in GitHub Desktop.

Basic file operations:

List the files in a directory

ls

List the files in a directory

  • -l : more details per file
  • -a : include hidden files (files starting with .) ls -la

Change directory

cd /var/log/
cd ~

mkdir -p a/b/c/d
cd a/b/c/d
cd -

System debugging:

Check file system disk space usage

df -h

wth is df?

man is your friend.

List block devices

lsblk

File System usage in current directory

du -sh .

Display current processes

top
htop

Text files:

Print contents of file

cat abc.txt

View contents of file

less abc.txt

View and edit contents of file

vim abc.txt # not for the faint hearted, i to insert, :wq to write + quit, :q to quit

vim image

Difference between two files

diff temp_text.txt altered_temp_text.txt

vim diff temp_text.txt altered_temp_text.txt

Search for strings in files

grep "a" abc.txt
grep "A" caps.txt
grep "a" caps.txt
grep -i "a" caps.txt
grep -n "z" abc.txt

View the first 15 lines of a file. Default is 10 lines.

head -n 15 /var/log/boot.logo

View the last 15 lines of a file. Default is 10 lines.

tail -n 15 /var/log/boot.log

Redirecting Input

ls > this_file.txt

ls | tee this_file.txt

Script tool

script my_script_recording --timing=time.log scriptreplay -s my_script_recording -t time.log

Print strings

echo "Hello!"
echo "I want to read this later." > strings.txt
echo "Will this erase what was there before?" > strings.txt
echo "This should not erase what was there before." >> strings.txt

View the last 10 lines and then any other file that gets written to it.

tail -f

Recursively look for a string in a directory

grep -nair "docker" ~/Learning/distsystems/

Screen Demo

screen

To leave it attached press Ctrl + a + d

Use this to get back to the previous screen

screen -r

This shows the list of screens currently active

screen -ls

Ctrl + R is your friend.

SSH

ssh -X bm5937@budapest.cs.rit.edu
gio open .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment