|
ls
|
List all values in present working directory
|
|
ls -R
|
List all files in sub-directories as well
|
|
ls -a
|
List hidden files as well
|
|
mv file "new file path"
|
Moves the files to the new location
|
|
mv filename new_file_name
|
Renames the file to a new filename
|
|
i
|
insert at cursor
|
|
a
|
Write after cursor
|
|
A
|
Write at end of line
|
|
ESC
|
Terminate insert mode
|
|
u
|
Undo last change
|
|
U
|
undo change to entire last line
|
# For loop in Bash; Basic
for x in 1 2 3
do
echo $x
done
1
2
3
# For loop in Bash; Range
{START..STOP..INCREMENT}
for x in {1..5..2}
do
echo $x
done
Output:
1
2
5
# For loop; Three expression
for ((x=2;x<=4;x+=2))
do
echo $x
done
Output:
2
4
|
cd
|
Navigate to home directory
|
|
cd ..
|
Move one level up
|
|
cd /
|
Move to root directory
|
|
ps
|
Display currently running processes
|
|
ps -ef
|
Display currently running processes on system
|
|
grep pattern files
|
grep 'word' filename
|
|
grep -i
|
Case insensitive search
|
|
grep -R 'httpd'
|
Look for all files in the current directory and in all of its subdirectories
|
|
grep -c 'nixcraft' frontpage.md
|
Search and display the total number of times that the string ‘nixcraft’ appears in a file
|
# Search for books in the book directory that contain air
for book in $(ls books/ | grep -i 'air')
do
echo $book
done
AirportBook.txt
FairMarketBook.tx
case 'STRING' in
PATTERN1)
COMMAND1;;
PATTERN2)
COMMAND2;;
*)
DEFAULT COMMAND;;
esac
case $(cat $1) in
*sydney*)
mv $1 sydney/ ;;
*melbourne*|*brisbane*)
rm $1 ;;
*canberra*)
mv $1 "IMPORTANT_$1" ;;
*)
echo "No cities found" ;;
esac
|
Creates a new file
|
cat > filename
|
|
Displays the file content
|
cat filename
|
|
Set with an equal sign
|
greeting="Hello"
|
|
Access with a $
|
echo $greeting
|
|
Direct Output of Second command to first
|
1st_command $ 2nd Command
|
|
Runs the 2nd command only if the 1st command runs successfully.
|
1stcommand && 2nd Command
|
|
Runs the 2nd command only if the 2nd command does not run successfully.
|
A || B # Run B if and only if A failed
|
Set a condition which is tested at each iteration:
x=1
while [ $x -le 3 ];
do
echo $x
((x+=1))
done
if then else:
x="Queen"
if [ CONDITION ];
if [ $x == "King" ];
then # SOME CODE
then echo "$x is a King!"
else # SOME OTHER CODE
else echo "$x is not a King!"
fi
fi
|
Alt + b
|
move backward one word
|
|
Alt + f
|
move forward one word
|
|
Alt + u
|
make entire word after cursor uppercase
|
|
Alt + c
|
make first letter after cursor uppercase
|
|
Alt + d
|
delete word after cursor
|
|
^a
|
beginning of line
|
|
^e
|
end of line
|
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.