YuWebdesign



Unix/Linux vs Windows Command Line Cheat Sheet

By YuwebDesign

Unix/Linux vs Windows Command Line Cheat Sheet

Windows Unix/
Linux
Command
Description
SHORTCUTS
ctrl+c ctrl+c
ctrl+z
abort, cancel current command
cls ctrl+L
clear
clear the command window
command_name – -help detailed information about command
home btn ctrl+a moves caret to the beginning of the line
end btn ctrl+e moves caret to the end of the line
ctrl+home btn ctrl+x erases characters to the left of the cursor
ctrl+end btn ctrl+k erases characters to the right of the cursor
esc key ctrl+u erases the whole line
F3 ctrl+r brings up a recent command
tab autocompletes what you have written
if unable to autocomplete hit tab twice and type a few more characters
F7 history prints a list of all recent commands
arrow up
F8 or F5
history of most recent commands
starting through the most recent commands
arrow down history of most recent calls
DIRECTORIES (Moving Around)
chdir pwd display path of the current working directory
cd ~
cd ~
go to home directory
cd\ or cd \
cd/ or cd /
cd / move to the root directory of current drive
e.g., C:\Windows\System32>cd\ takes you to C:\>
cd\drive:absolute_path\dir_name

cd /drive:absoute_path/dir_name

cd /drive:absolute_path/dir_name
cd ~/absolute_path
go to directory dir_name
absolute path from root drive

e.g., get to C:\Windows\Temp directory by cd\windows\temp
regardless of where you are on the C: drive.
cd ~/dir_name – move to dir_name within home

cd relative_path/dir_name go to directory dir_name
relative path from root drive
cd sub_directory
same as
cd ./sub-directory
go to sub_directory
one level deeper
(one directory down)
cd .. move to the parent directory
(one directory up)

e.g., from /usr/bin/tmp, cd .. moves you to /usr/bin,
cd ../.. moves you to /usr (i.e. up two levels)
from /usr/bin/tmp, you can cd ../../local to /usr/local

DIRECTORIES (List Contents)
dir [drive:][path][filename] [/A[[:]attributes]] [/B] [/C] [/D] [/L] [/N]
[/O[[:]sortorder]] [/P] [/Q] [/R] [/S] [/T[[:]timefield]] [/W] [/X] [/4]

Colon [:] is optional, no spaces. Read more at Microsoft

ls [options] [file|dir]

Read more at Linux

list directory contents
dir displays names of all files (except hidden and system files).

dir /a displays names of all files (including hidden and system files).

dir /a[:]d Directories
dir /a[:]r Read-only files
dir /a[:]h Hidden files
dir /a[:]a Files ready for archiving
dir /a[:]s System files
dir /a[:]i Not content indexed files
dir /a[:]l Reparse Points
dir /a[:]- Prefix meaning “not”

ls list files and directories without additional info
ls -la list detailed directory contents (including hidden files)
ls -a list directory contents (including hidden files)
ls -l list sub-directories only (with extra information)
ls -lh list long format with human readable file size
ls -ls list long format with file size
ls -lS Sort files by file size ascending.
ls -s list file size
ls -S sort by file size
ls -r display files and directories in reverse order
ls -R Recursively list sub-directories (directory trees)
ls -F list files and directories (add ‘/’ character at the end of each directory)
ls -ltr Reverse Output Order (latest modification file or directory date)
ls -i Display inode number of file or directory
ls -n Display UID and GID of files and directories
ls -t sort by time & date
ls -X sort by extension name
Options for listing directory contents
CREATE (File or Directory)
md directory_name
mkdir directory_name
mkdir directory_name make directory named directory_name
type nul > filename.extension touch filename.extension create file filename if not exists
update file access and modification time if file exists
DELETE (File or Directory)
del file_name.extension
erase file_name.extension
rmdir dir_name
rm file_name.extension
rm dir_name
delete file named file_name
or directory named dir_name
rm –f file_name force-delete file named file_name
rm –r directory_name delete directory_name
rm –rf directory_name force delete directory_name
RENAME, MOVE (Files or Directories)
rename file1 file2
ren file1 file2
mv file1 file2 rename file1 to file2
move file directory mv file directory move file to directory
(possibly overwriting an existing file)
COPY (Files or Directories)
copy filename.extension path/directory_name cp filename.extension path/directory_name copy filename.extension to directory_name
copy file1 file2 cp file1 file2 copy file1 to file2
copy file directory cp file directory copy file to directory
(possibly overwriting an existing file)
copy directory1 directory2 cp directory1 directory2 copy directory1 and its contents to directory2
(possibly overwriting files in an existing directory)
robocopy directory1 path/directory2 rsync
read more
copy directory1 contents to directory2
SEARCH and COMPARE
where file_name show possible locations of file_name
locate [options] filename
find [options] filenamefind -name filename
find -name *.txt find file ending at .txt
find -name filename* find filename starting with filename
find all instances of file file_name
find [switch] “String” path/filename

switch (optional):
/v – show lines not containing the string of words you specified.
/c – count how many lines contain your search terms.
/n – shows the numbers that correspond with the lines.
/i – ignore the case of text you are searching for.

grep [options] pattern [files]

-c : Prints only a count of the lines that match a pattern
-h : Display the matched lines, but do not display the filenames.
-i : Ignores, case for matching
-l : Displays list of a filenames only.
-n : Display the matched lines and their line numbers.
-v : This prints out all the lines that do not matches the pattern
-e exp : Specifies expression with this option. Can use multiple times.
-f file : Takes patterns from file, one per line.
-E : Treats pattern as an extended regular expression (ERE)
-w : Match whole word
-o : Print only the matched parts of a matching line,
with each such part on a separate output line.

search for patterns within file
e.g. grep word-or-phrase thisfile.txt
fc path\file1.txt path\file2.txt diff path\file1.txt path\file2.txt compares file contents
OUTPUT
type file_name cat file_name output the contents of file_name
more file_name output the contents of file_name
less file_name output contents of file_name using the less command
head file_name output the first 10 lines of file_name
tail filename output the last 10 lines of filename
COMMANDS
command1&&command2 comand2 runs only if command1 completes successfully
command1||command2 command2 runs only if command1 fails
command1;command2 combines commands
instead of waiting for each command to finish
before typing the next one
command1 | command2 direct the output of command1 to command2
command > [path/]output.txt standard output stream will be redirected to the file only,
it will not be visible in the terminal.

If the file already exists, it gets overwritten.

command >> [path/]output.txt standard output stream will be redirected to the file only,
it will not be visible in the terminal.

If the file already exists,
the new data will get appended to the end of the file.

command 2> [path/]output.txt standard error stream will be redirected to the file only,
it will not be visible in the terminal.

If the file already exists, it gets overwritten.

command 2>> [path/]output.txt standard error stream will be redirected to the file only,
it will not be visible in the terminal.

If the file already exists,
the new data will get appended to the end of the file.

command &> [path/]output.txt Both the standard output and standard error stream
will be redirected to the file only,
nothing will be visible in the terminal.

If the file already exists, it gets overwritten.

command &>> [path/]output.txt Both the standard output and standard error stream
will be redirected to the file only,
nothing will be visible in the terminal.

If the file already exists,
the new data will get appended to the end of the file.

command | tee [path/]output.txt command | tee ~/outputfile.txt standard output stream will be copied to the file,
it will still be visible in the terminal.

If the file already exists, it gets overwritten.

command | tee -a [path/]output.txt standard output stream will be copied to the file,
it will still be visible in the terminal.

If the file already exists,
the new data will get appended to the end of the file.

command |& tee [path/]output.txt

command 2>&1 | tee [path/]output.txt

command |& tee ~/outputfile.txt

command 2>&1 | tee ~/outputfile.txt

Both the standard output and standard error streams
will be copied to the file
while still being visible in the terminal.

If the file already exists, it gets overwritten.

command |& tee -a [path/]output.txt

command 2>>&1 | tee [path/]output.txt

Both the standard output and standard error streams
will be copied to the file while still being visible in the terminal.

If the file already exists,
the new data will get appended to the end of the file.

PERMISSIONS
(owner-group-anyone)
0 = (—) = 000 (in binary) none
1 = (–x) = 001 (in binary) execute
2 = (-w-) = 010 write, modify
3 = (-wx) = 011 write + execute
4 = (r – -) = 100 read only, access
5 = (r-x) = 101 read + execute
6 = (rw-) = 110 read + write
7 = (rwx) = 111 read + write + execute
chmod 644 file_name change permission of file_name to 644
owner (rw-), group (r–), everyone (r–)
ideal for files
chmod 664 file_name change permission of file_name to 664
owner (rw-), group (rw-), everyone (r–)
ch mod 755 file_name change permission of file_name to 755
owner (rwx), group (r-x), everyone (r-x)
ideal for folders
chmod 775 file_name change permission of file_name to 775
owner (rwx), group (rwx), everyone (r-x)
chmod 777 file_name owner (rwx), group (rwx), everyone (rwx)
use sparingly
chmod octal file_name change the permissions of file_name to octal

drwxrwx— = 700 =
read, write, & execute for owner and group

chmod –R 600 dir_name change permission of directory dir_name to 600
chown user_name:group_name file_name change ownership of file to user_name and group_name
(add –R to include directory contents
PROCESSES
ps ax = ps output currently running processes
top display live information about all currently running processes
kill pid end process with id pid
kill all p_name kill all processes named p_name
bg lists stopped or background jobs,
resume stopped job in the background
fg brings the most recent job to the foreground
fg job_name brings job job_name to the foreground
SYSTEM
date show current date
cal show this month’s calendar
whoami Who you are logged in as
finger user_name display information about user_name
df show disk user
du show directory space usage
shutdown shuts down the computer
NETWORK
nslookup url finds the IP address of any website
ipconfig displays internet protocol configuration
netstat displays information about existing connections to your PC
net view displays a list of domains, computers, or resources
in your current domain
ping host_name ping host_name and display status
whois domain_name get whois information for
dig domain-name get DNS information for
dig –x host_name reverse lookup host
wget file_name download file_name
wget c file_name continue a stopped download for file_name
ssh user_name@host_name connect to host_name as user_name
ssh -p port_number user_name@host_name connect to host_name on port_number as user_name
ssh-copy-id user_name@host_name add your key to for
to enable a keyed or password-less login

Leave a Reply or Comment

Your email address will not be published. Required fields are marked *