-
Notifications
You must be signed in to change notification settings - Fork 0
Commands
Below, we list several of the most commonly used linux commands. Please note that each command can take multiple options (flags) to perform specialized operations. To view all the options a command can have as well as its documentation use man or for a shortened version, use the flag "--help" after the command.
Prints given text to the terminal.
> echo Hello World
Hello World
Print Working Directory. Shows the directory we are in. If we are for example in a directory "folder1 " inside the home folder:
> pwd
/home/kali/folder1
Shows our user's name.
> whoami
kali
Show directory content.
Lets say we are in a directory like this:
.
file2
file2
file3
folder
file3
file4
> ls
file1 file2 file3 folder
> ls folder
file3 file4
Moves us to a directory.
> ls
file1 file2 file3 folder
> cd folder
> ls
file3 file4
Creates a new file.
> ls
file1 file2 file3 folder
> touch new
> ls
file1 file2 file3 folder new
Creates new directory.
> ls
file1 file2 file3 folder
> mkdir newdir
> ls
file1 file2 file3 folder newdir
Copies file to destination(can also rename the copy).
> ls
file1 file2 file3 folder
> ls folder
file4
> cp file1 folder
> ls folder
> ls
file1 file2 file3 folder
file4 file1
> ls
file1 file2 file3 folder
> cp file1 file6
> ls
file1 file2 file3 folder file6
Moves file to new destination (also used to rename).
> ls
file1 file2 file3 folder
> ls folder
file4
> mv file1 folder
> ls folder
> ls
file2 file3 folder
file4 file1
> ls
file1 file2 file3 folder
> mv file1 file6
> ls
file6 file2 file3 folder
Remove (delete) or directory.
> ls
file1 file2 file3 folder
> ls folder
file4
> rm file1
> ls
file2 file3 folder
> ls
file1 file2 file3 folder
> rm -r folder
> ls
file1 file2 file3
Change permissions of file
you can use -
to remove a permission or +
to add a permission.
For examlpe to add executable permission:
> ls
file1 file2 file3 folder profram
> ./program
zsh: permission denied: ./program
> chmod +x program
> ./program
/** success **/
Shows what's inside the file.
> ls
file
> cat file
Lorem ipsum dolor sit amet consectetur adipisicing elit. Maxime mollitia,
molestiae quas vel sint commodi repudiandae consequuntur voluptatum laborum
numquam blanditiis harum quisquam eius sed odit fugiat iusto fuga praesentium
optio, eaque rerum! Provident similique accusantium nemo autem. Veritatis
obcaecati tenetur iure eius earum ut molestias architecto voluptate aliquam
nihil, eveniet aliquid culpa officia aut! Impedit sit sunt quaerat, odit,
tenetur error, harum nesciunt ipsum debitis quas aliquid. Reprehenderit,
quia. Quo neque error repudiandae fuga? Ipsa laudantium molestias eos
Simple text editor for the terminal.
> ls
file
> nano file
*opens file in editor*
Show difference of 2 files.
> ls
file1 file2
> cat file1
same
diff1
same
diff2
> cat file2
same
diff-1
same
diff-2
> diff file1 file2
> diff1
< diff-1
---
> diff2
< diff-2
Shows the "manual" of a command. Most commands also accept the switch --help
or -h
(see switches), although for many man
is more complete.
> man ls
NAME
ls - list directory contents
SYNOPSIS
ls [OPTION]... [FILE]...
DESCRIPTION
List information about the FILEs (the current directory by default). Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.
Mandatory arguments to long options are mandatory for short options too.
-a, --all
do not ignore entries starting with .
-A, --almost-all
do not list implied . and ..
--author
with -l, print the author of each file
-b, --escape
print C-style escapes for nongraphic characters
......
The package manager downloads packages.
> sudo apt install program
# =====----- 50% #
program installed successfully
Search a directory for files (exc by name)
> ls
file1 file2 folder
> ls folder
file3 file4 file_i_look_for
> find . -name file_i_look_for
./folder/file_i_look_for
Searches a file for a word/patern.
>ls
file
> cat file
apple
bread
milk
chocolate
milkshake
> grep milk file
milk
milkshake
Starts ssh client to establish secure connections(SSH stands for Secure Shell). Essentially allows you to remotely connect, interact and execute commands on a remote machine. Syntax: ssh user@host
> ssh [email protected]
Opens file with default program( like double clicking). It can also open directories in file explorer (if filegiven is a directory).
can map one command to another.
> alias say="echo"
> say Hello World
Hello World
what i like to do is alias xdg-open
to just open
(alias open="xdg-open"
)
This way, open image.png
opens image in image viewer and open file.py
opens it in a graphical editor (because nano sucks and vim is complecated for new users)
Warning: this makes it work only for current terminal session. If you want to make aliases permanent ask me.