Unix Flashcards
Where I am - Print working directory
pwd
List current directory content
ll, ls -al
read content of a file
cat fileName
clear the screen
clear
How to find unix version
cat /etc/issue
How to find cpu details
cat /proc/cpuinfo
How to find RAM on m/c
free -mto
Change directory
cd dirName
Go to root directory
cd /
Go to home directory
cd ~
Go to parent directory
cd ..
How to see command history
history
How to run a command from history
! CommandNumberFromHistoryList
Remove particular command from shell history
history – d
How to identify Directory/File in ls -al output
dxyzxyzxyz _xyzxyzxyz
How to identify link in ls -al output
lxyzxyzxyz
How to identify hidden file or directory in ls -al output
fileName/DirName will be prefixed with period
Tab completion
Tab - only one, Tab+Tab - if multiple files starts with same char.
Piping
ls | less
Chuck output into pages
less
Go to next page in Less output
Spacebar
Quit from Less output prompt
q
Is UNIX case sensitive
yes
How to get help on cat command
man cat
Copy file myFile to myNewFile
cp myFile myNewFile
Copy directory myDir to myNewDir
cp -r myDir myNewDir
Make folder myFolder
mkdir myFolder
Delete a file myFile
rm myFile
Rename a file myFile to myNewFile
mv myFile myNewFile
Wildcards
- one or more
Delete a dir myDir
rm -r myDir
duuugggooo USER GROUP
d=dir, uuu=user rwx permissions
What does x permission mean for directory
user can explore the folder
permission groups
u=user, g=group, o=other, a=all, r=read, w=write, x=execute,+=add permission, -=remove permissions, ==assign
Command to change permission on file/dir
chmod - Change Mod
who is the super user in unix
root
super user do
sudo followed by command. you will be prompted for password
change owner - user
chown newOwnerName fileName,
sudo chown newOwnerName fileName
change owner -user+group
chown newOwnerName:newGroupName fileName
How to zip a file
zip zippedFileName.zip fileName.txt
How to unzip a file
unzip zippedFileName.zip
Hot to GNU zip(older system)
gzip fileName.txt
This will replace the original file and append .gz
Unzip GNU zip
gunzip fileName.txt.gz
This will replace the original file.
Which offers better compression zip or gzip
gzip
What is tar ball
No compression, just bundling multiple files into single file.
How to create a tar ball
tar -cvf tarFileName.tar form*
How to extract a tar ball
tar -xvf tarFileName.tar
How to create compressed tar ball
tar -cvfz tarFileName.tgz form*
How to extract a compressed tar ball
tar -xvfz tarFileName.tgz
How to create symbolic link(shortcuts)
ls -s fullFilePath OptionalLinkName
SSH(Secure Shell)
ssh -p8080 userName@serverName
will be prompted for password.
How to terminate SSH session
exit
Secure Copy
scp FROM TO
scp -r -P8080 userName@serverName:fullPath localPath
create a blank test.txt file
touch test.txt
How to find test.txt against database
locate test.txt
How to update database
updatedb [updatedb generally runs on CRON Job]
How to find test.txt without using database
find pathToSearch -name fileName
find / -name test.txt
GREP
Global Regular Expression Print
Search for “theme” in index.php
grep ‘theme’ index.php
Search for “theme” in all files in current directory
grep ‘theme’ *
Search for “theme” in all files in current directory and child directories
grep -r ‘theme’ *
How to display line# in grep output
-n flag
How to just display file names in grep output
-l flag
How to find all files which does not meet grep criteria
-v flag
How to ignore case in grep search
-i flag
How to find location of a command
which commandName e.g which vi
vi editor - How to move cursor
arrow keys or HJKL
vi editor - How to move cursor multiple times
7J
vi editor - command mode/insert mode
esc=Enter command mode, insert=Enter insert mode.
Goto line #
:10 - will take you to line 10
:1 - will take you to first line.
Goto bottom of file
G(capital)
start/end of line
0=start of line, $=end of line
Delete entire line
dd
Undo
u
Discard all changes till last save(:w)
:e!
Save document in current state
:w
Save and quit
:wq
Force quit
:q!
copy
yy=copy entire line, 3yy=copy 3 lines, yw=copy word
paste
p
copy selected text
y=yanked
How to find differences
diff fileName1 fileName2
Where alias are stored
Unix=.bashrc, MAC=.bash_profile
How to create alias
alias ll=”ls -al” and start new terminal session.
How to read from top of a file
head fileName
How to read from bottom of a file
tail fileName
How to tail and follow from a file
tail -100f fileName
How to identify which shell is in use
echo $SHELL