Basic Linux commands for devs (flipped) Flashcards
use to get more details about the specified command and arguments that can be used with it
man {command}
“Present working directory”. prints the path to the current directory
pwd
used to open the specified file or internet URL
open {filename/url}
list all files and folders in the current directory
ls
-a : adds hidden elements
-l : long format (adds more information)
-al : does both
used to create a new folder/directory
mkdir {name}
can also make multiple at once by adding space separated names ex.
mkdir folder1 folder2 folder3
-p: create nested folders
ex:
mkdir -p foler1/nested
used to create new files.
touch {name}
ex:
touch file.txt
touch file.txt file2.py
used to remove empty folders
rmdir
ex:
rmdir folder
used to remove empty or non-empty folders/directories/files
rm
ex:
rm file.txt
rm -d empty_folder
rm -r non_empty_folder
rm -r * (removes all files/folders in current directory)
note:
files will not be moved to recycle bin, it is a permanent deletion.
used to copy files into the target folder
cp {file} {folder}
ex:
cp file1.txt folder
used to move files into the target folder
mv {file} {folder}
ex:
mv file1.txt folder
used to show all commands that have been typed into the Linux shell.
history
used to show the difference between two files
diff {file1} {files2}
used to show the first {10 lines default} of a file
head {filename}
ex:
head -n 15 logfile.txt
{will show the first 15 lines of logfile.txt}
used to show the last{10 lines default} of a file
tail {filename}
ex:
tail -n 15 logfile.txt
{will show the last 15 lines of logfile.txt}
used to print messages/variable values to the terminal.
echo {msg/$variable}
ex:
echo $username
{prints value of username}
echo *.txt
{prints all txt files in the dir to terminal}
pings the given address to check connectivity.
ping {url / IP address}
note:
will run indefinitely every second until killed with {cntrl + C}
change the current working directory.
cd {path}
cd ../ : moves up one level to parent directory
print the contents of a file to the console. Can also append or overwrite file contents between two files.
cat {filename}
“short for concatinate”
cat >{filename}
{file contents} : will create a new file with the contents inside
cat {file1}»_space; {file2.txt} : will add the contents of file1 to file2.
cat {file1} > {file2.txt} : will copy and OVERWRITE contents of file1 into file2
Display a real-time list of processes running on the machine (similar to task manager on windows)
top
note: will run until you hit “q”
used to set up shorthands of commands used frequently to avoid retyping.
alias {alias name}=”{command}”
used to remove a shorthand for a command that was set up previously.
unalias {alias name}
allows you to view files without opening an editor.
less {filename}
create, view, and edit files in the terminal window.
nano {filename}
input/edit file contents -> “Cntrl + X” -> “y” to save.
create, view, and edit files in the terminal window WITH VIM.
vim {filename}
input/edit file contents -> “Cntrl + X” -> “y” to save.