Monday, July 21, 2014

Know the Physical RAM Size: Linux/Unix

Commands:

1. less /proc/meminfo
2. free -m
3. vmstat -s
4. gnome-system-monitor
5. sudo dmidecode --type memory

Monday, July 7, 2014

find: Make UNIX easy



Description Command
find a file in a directory find <directory> -name “<file/dir name>”
case insensitive find -i (eg: find . -iname '<file/dir name>'


find for regular file types find . -name '<name>' -type f
find for directories types find . -name '<name>' -type d
find for symbolic links find . -name '<name>' -type l


find all empty files in a directory find . -empty


execute another command on the find results:
Syntax: <find command> -exec <other command> {} \;

grep: Make UNIX easy

Global search for a Regular Expression and Print



Description Command
Match count -c
case insensitive search -i
recursive search -r
select non-matching lines -v
show matched text in color --color
show matched text and next n lines after it -A n (eg: grep -A 3 "example" demo.txt
show file name along with matched line -H
exclude hidden directories in search results --exclude="\.*" (eg: grep -iHr --exclude="\.*" "text" *
show line numbers -n
search in only specific file types *.fileType (eg: grep -n "print" *.java)

jar: Make UNIX easy

1. unjar a jar file
jar -xf file.jar

2. List files in jar file, without extracting it
jar -tvf file.jar

3. unzar to a specific directory
unzip file.jar -d destinationDir

vi: Visual Editor: Make UNIX easy


Description Command
Go to start of file gg
Go to end of file G (Shift + g)
Go to start of line 0 (zero)
Go to end of line $ (dollar)
Highlight similar words # (Press # with curson on required word)


Go to next line j
Go to previous line k
Go to next character h
Go to previous character l


Delete current character x
undo last action u
redo Ctrl + u


Delete a line dd
Delete all lines, from current line to end of the file dG
Delete all lines, from current line to start of the file dg


Copy Use mouse to copy required lines
Paste Shift + Insert
Refresh the current file :e (