Commandline Cheatsheet
Improve your Commandline usage with these Dns and Navigational terminal commands and functions.
DNS commandline functions
NSlookup
To query the domain example.com, type:
nslookup example.com
This will return all the domain information, such as
- The IP address,
- Name servers,
- other related information.
Specific to see the Nameservers
You can use the nslookup command in the command line to check where a domain’s name servers are pointing. Here’s how you can do it:
1
nslookup -type=NS example.com
Dig
The dig command is a powerful tool used to query DNS servers for information about a domain name. It can be used to find out the IP address of a domain, the mail server associated with a domain, and other information.
To use the dig command, open a command line window and type in the following command:
dig example.com
You can also use the dig command to query specific types of information. For example, to query the mail server associated with a domain, type in the following command:
1
2
3
dig example.com MX
dig example.com A
dig example.com NS
This will return the mail server associated with the domain.
You can also use the dig command to query other types of information, such as the nameservers associated with a domain. For more information, type in the following command:
1
dig -h
Host
The DNS host command is used to look up the IP address associated with a domain name. To use the DNS host command on the command line, open a terminal window and type the following command:
1
host https://example.com
Replace example.com with the domain name you want to look up.
The command will return the IP address associated with the domain name.
Whois
The whois command is used to look up information about a domain name or IP address.
To use the whois command, open a command line interface (CLI) such as the Windows Command Prompt or the Mac OS X Terminal.
At the prompt, type the command whois followed by the domain name or IP address you want to look up.
For example, to look up information about the domain name example.com, type the following command:
1
whois example.com
Find out who the DNS registrar is.
The who is command is also good to find out who the DNS register is. This will provide the name of the registrar and the person who registered the domain name.
1
whois example.com
Navigation terminal commands
Go to start of line
Cursor to the start of the line
Ctrl a
Go to end of line
Cursor to the end of the line
Ctrl e
Clear prompt
Ctrl + U:
Clears the entire line before the cursor.
Change directory
cd
: change directorycd a/
: change directory to a (which is a directory in my current directory)cd /opt/
: change directory to opt (full path start with /)cd ../
:one directory upcd ./
: this directorycd
: return home directory for your user
Ctrl + K: Clears the entire line after the cursor. Ctrl + W: Deletes the word before the cursor. Ctrl + A: Moves the cursor to the beginning of the line. Ctrl + E: Moves the cursor to the end of the line.
Repeat last command as sudo
If you forget to use your sudo prefix. Repeat the last command with sudo.
1
sudo !!
Recursively search through history of commands
ctr r
Type history then enter to see a history of commands
Built in commandline functions to help you work with text files
cat
: concatenate files and print on the standard outputcat > a.txt
: start a file creationcat a.txt
: show file contentcat a.txt b.txt
: show files content respectivelycat a.txt b.txt > c.txt
: create a file which contains a.txt and b.txt
Working with system Users and file permissions
chmod
: change file mode bitschmod +x a.txt
: All users and groups have the execute permissionchmod $u$g$o a.txt
: Give specific user permission- $u -> current user permission number
- $g -> current user’s group permission number
- $u -> others permission number
- permission number can calculate with:
- 0 -> no permission
- 1 -> x (execute)
- 2 -> w (write)
- 4 -> r (read)
chmod 651 a.txt
: it means user can write and read, group can read and execute, others can only execute.
Copy
cp
: copy files and directoriescp $source $destination
: copy the file from source to destionationcp -R a/ b/
: copy directory(folder) to other folder. (-R = -r = –recursive)
date
: print or set the system date and timeecho
: display a line of text, args etc.echo "string"
: it prints out “string”echo $PATH
: it prints $PATH variable’s value
grep
: print lines matching a patterncat b.txt | grep q
: the lines which containsq
in b.txt.cat b.txt | grep q$
: the lines which ends withq
in b.txt.cat b.txt | grep ^q
: the lines which starts withq
in b.txt.- ! for regex usage you can only specify the -E(or -e):
cat b.txt | grep -E q$
.
head
: output the first part of fileshead b.txt
: first 10 lines of the b.txt (default)head b.txt -n 4
: first 4 lines of the b.txt
List
ls
: list directory contentsls
: list current directory contents (only general files ignore hidden files(which starts with.
))ls a/
: list directorya
’s contentsls -l
: list current directory contents (long list format)ls -a
: list current directory all contents (do not ignore hidden files)ls -la
: all file in long list format
more
: file perusal filter for crt viewingmore b.txt
: paginate the contents of the b.txtcat b.txt | more
: this also paginates
less
: opposite of moremkdir
: make directories- mkdir NEWFOLDERNAME: create a folder(directory) name NEWFOLDERNAME
Move
mv
: move (rename) filesmv $source $destination
: move folder and files from source to destination (you can use it to rename a folder or file)
pwd
: print name of current/working directoryrm
: remove files or directoriesrm b.txt
: delete file namedb.txt
rm -r a/
: delete folder nameda
rmdir
: remove empty directoriesrmdir a/
: delete directory if and only if the directory is empty
export
: set an environment variableexport VARIABLE_NAME="VALUE OF VARIABLE"
: it creates a variable named VARIABLE_NAME. (access name $VARIABLE_NAME)
sort
: sort lines of text filesqtail
: output the last part of filestail b.txt
: last 10 lines of the b.txt (default)tail -n 4 b.txt
: last 4 lines of the b.txt
tar
: The GNU version of the tar archiving utility (tape archive)tar -tvzf foo.tar.gz
: list all files name in foo.tar.gztar -zcvf archive-name.tar.gz directory-name
: create a tar.gz file from directory-nametar -xvzf foo.tar.gz
: uncompress all files in foo.tar.gz- -z: using gzip program
- -x: extract (uncompress)
- -c: create archive
- -v: verbose (display progress while creating archive)
- -f: archive file name
ssh
ssh
: OpenSSH SSH client (remote login program)ssh eng1.mu.edu.tr
: connect the eng1.mu.edu.tr server with SSH (it get your current username as a username in the server).ssh mo.tercanli12@eng1.mu.edu.tr
: connect the server with username: mo.tercanli12
Word and byte Count
wc
: print newline, word, and byte counts for each filewc b.txt
: prints out the number of Lines, Words, Characterswc -l b.txt
: only number of lineswc -w b.txt
: only number of wordswc -c b.txt
: only number of character
Secure Copy
scp
: secure copy (remote file copy program)scp your_username@remotehost.edu:foobar.txt /some/local/directory
: copy file from remote to localscp foobar.txt your_username@remotehost.edu:/some/remote/directory
: copy file from local to remote
wget
: The non-interactive network downloader.wget $URL
: download url content from $URLwget $URL -O a.txt
: download url content from $URL and save it asa.txt
curl
: transfer a URLfind
: search for files in a directory hierarchyman
: an interface to the on-line reference manualsman tar
: manual page for tar
sed
: stream editor for filtering and transforming textsed s/one/ONE/
< a.txt: it process the filea.txt
and allone
becomeONE
. (a.txt does not change)
awk
: pattern scanning and processing language