Basic - Terminal
- Benefits
- Gives greater Control, Speed & Efficiency
- Access remote servers, Headless OS
- Command line tools
- Difference
- Terminal
- Tool that you use to type and execute commands
- Used to be a hardware
- Command Line
- The interface of the terminal
- Shell
- The program that the terminal runs
- The "OS" of the terminal
- Key Commands
Up Arrow
=> Shows your last command
Down Arrow
=> Shows your next command
Tab
=> Auto-complete your command
Ctrl + L
=> Clear the screen
Ctrl + C
=> Cancel a command
Ctrl + R
=> Search for a command
Ctrl + D
=> Exit the terminal
- Manual Command
man command
=> Manual of any command, q
to exit
command --help
=> For windows
whoami
=> Shows you the current user that you are logged in as
date
=> Shows you the current date and time
- Navigation
pwd
=> Lists the path to the working directory
ls
=> List directory contents
ls -a
=> List contents including hidden files (Files that begin with a dot)
ls -l
=> List contents with more info including permissions (long listing)
ls -r
=> List contents reverse order
cd
=> Change directory to home
cd dirName
=> Change directory to specific directory
cd ~
=> Change to home directory
cd ..
=> Change to parent directory
cd -
=> Change to previous directory (which could be different than the parent of course)
cd /
=> Change to root directory
find dir1 -name fileName
=> Find location of a program
- Opening a Folder/File
open dirName
=> Mac
start dirName
=> Windows
xdg-open dirName
=> Linux
- Modifying Files & Directories
mkdir dirName
=> Make directory
touch fileName
=> Create file
> fileName
=> Can start typing after creation
touch file-{001..100}.txt
=> Create 100 files
rm fileName
=> Remove file
rm -i fileName
=> Remove directory, but ask before
rm -r dirName
=> Remove directory
rm -rf dirName
=> Remove directory with contents
rm ./*
=> Remove everything in the current folder
cp fileName dirName
=> Copy file
mv fileName dirName
=> Move file
mv dirName dirName
=> Move directory
mv fileName1 fileName2
=> Rename file or folder
mv fileName fileName -v
=> Rename Verbose - print source/destination directory
- View content of File
cat fileName
=> Display contents of file
cat fileName2 fileName1
=> View contents of multiple file
cat > fileName
=> Can start typing
cat >> fileName
=> Append to a file
cat -n fileName
=> Show line numbers
less fileName
=> q
to exit, Scroll using arrows or page up/down
more fileName
=> See content of big file, space
for next page, enter
for next line, q
for exit
head fileName
=> Shows first 10 lines of file by default
tail fileName
=> Shows last 10 lines of file by default
echo "value"
=> Display the value
echo "value" > fileName
=> Write to a file
echo "value" >> fileName
=> Append to a file
- Searching
grep searchTerm fileName
=> Returns line that matches the given pattern, Can also use regular expression
find dirName -name fileName
=> Returns names of files that matches the filename
.
represents current directory
find dirName -empty
=> Returns empty files
find dirName -name fileName -delete
=> Deletes file
- Piping
- Way of redirecting standard output to another destination, such as another file
find dirName -name fileName > fileName1
=> Pipe the result from our find into a new file
- Symlink
- A symlink is a special type of file that points to another file
- It is a shortcut to the original file
- It is useful when you want to access a file in a different location without having to copy it
ln -s fileName symlinkName
=> Create a Symlink
mklink symlinkName fileName
rm symlinkName
=> Remove a Symlink
- History
history
=> Displays the history of commands
!100
=> Run the 100th line from history