Basic Linux Commands on Linux and Windows Operating Systems

This writing is useful for those that wish to get started with Linux commands. Here you will find the most common commands that are used in Linux.

If you would like to run Linux commands on Windows then install Cygwin. Cygwin is a Linux layer on top of Windows that allows you to use Linux commands in Windows.

If you install Cygwin on Windows then the default path when you start the Cygwin terminal will be:

C:\cygwin64\home\{username}

 

Create new notepad file example

touch textfile.txt

 

Change directory

cd {directory path\name}

 

List directory content in long format ( -l ) including hidden files and directories ( -a )

ls -l -a

ls -al

 

Order files and directories by the time they were last modified

ls -t

 

List directory with pause and scrolling

ls -l | less

 

Show current location (print working directory)

pwd

 

Extract last 100 words of a file

tail -100 {filename.extension}

 

Extract first 100 rows of a file

head -100 {filename.extension}

 

Copy a file

cp {source} {destination}

 

Move a file

mv {source} {destination}

 

Make a new directory

mkdir {new directory name}

 

Delete file

rm {filename}

 

Delete an empty directory

rmdir {directory to remove}
rm -d{directory to remove}

 

Delete directory and its contents

rm -r {directory to remove}
rm -R{directory to remove}

 

Sort the contents of a file

sort {filename to sort}

 

Remove duplicate entries in a file

uniq {filename to remove duplicates}

 

Compress files

gzip {filename}

 

Compress directory

gzip -r {directory name}

 

Count the number of rows and words in a text file

wc {filename}

 

Search text within files for matching string pattern (case sensitive)

grep 'word' {filename}

 

Search text within files for matching string pattern (case insensitive)

grep -i 'word' {filename}

 

Search with a directory

grep -R Arctic /home/ccuser/workspace/geography

 

Display content of a text file

cat

 

sed stream editor (similar to find and replace)

sed 's/snow/rain/' forests.txt

 

Change file and directory permissions

chmod {options} {permissions} {filename}

 

List recent commands used

history

 

Automatically schedule tasks

cron
crontab

 

Change file permissions

chmod {permission number} {some file or directory}
chmod 777 /storage

 

Change recursive file permissions

chmod -R {permission number} {some file or directory}

 

 

Leave a Reply