Phipps Electronics

Order within the next 

FREE SHIPPING OVER $199

50,000+ ORDERS

WORLDWIDE SHIPPING

SSL SECURED

Basic Linux Commands

Contents

Here are some basic Linux commands to get you up and running, or a quick cheat sheet. Great for when working on a Raspberry Pi or any other single board computers which use Linux commands such as Beagleboard / Beaglebone, Asus Tinker Board and many others.

Files and Navigating

CommandDescription
lsDirectory listing (list all files/folders on a current directory)
ls -lDirectory listing, with the file details in a formatted way, easier to read
ls -laDirectory listing the same as ls -l but this will also display hidden files
cd dirChange directory to dir (dir will be directory name)
cd ..Change to the parent directory
cd ../dirChange to dir in the parent directory (dir is replaced with a specific directory)
cdChange to the home directory
pwdShow current directory
mkdir dirCreate a directory dir (replace dir with your chosen name)
rm fileDelete a file
rm -f dirForce remove a file
rm -r dirDelete directory dir
rm -rf dirRemove directory dir
rm -rf /If run by a superuser, will delete every file on the system (DO NOT DO THIS)
cp file1 file2copy file1 to file2
mv file1 file2Rename file1 to file2
mv file1 dir/file2Move file1 to dir as file2
touch fileCreate or update file
cat fileOutput contents of a file
cat > fileWrite standard input into a file
cat >> fileAppend standard input into a file
tail -f fileOutput contents of a file as it grows

Networking

CommandDescription
ping hostPing host
whois domainGet whois for a domain
dig domainGet DNS for domain
dig -x hostReserve lookup host
wget fileDownload file
wget -c fileContinue a stopped download
wget -r urlRecursively download files from a URL
curl urlOutputs the webpage from a URL
curl -o hello.html URLWrites the page to hello.html
ssh user@hostConnect to host as user
ssh -p port user@hostConnect using port
ssh -D user@hostConnect & use bind port

Processes

CommandDescription
psDisplay currently active processes
ps auxDetailed outputs
kill pidKill process with process id (pid)
killall procKill all processes named proc

System Information

CommandDescription
dateShow current date / time
uptimeShow uptime
whoamiCurrently logged in user
wDisplay who is online
cat /proc/cpuinfoDisplays CPU information
cat /proc/meminfoDisplays memory information
freeShow memory and swap usage
duShow directory space usage
du -shDisplays readable sizes in GB
dfShow disk usage
uname Add "-a" after the command to show all kernal information, for more specific information the following switches can be used "-m, -r, -v, -n"
sudo -lshwCalls the lshw tool which gathers vast information about the computer’s hardware such as CPU, disks, memory, USB controllers etc
lscpuDisplay CPU information
lsusbDisplays USB controllers information
lspciDisplays PCI devices information

Compressing

CommandDescriptionSwitchesSwitch Description
tar cf file.tar filesTar files into file.tar
tar xf file.tarUntar into a current directory
tar tf file.tarShow contents of archivecCreate an archive
tTable of contents
xExtract
zUse zip / gzip
fSpecify a filename
jBzip2 compression
wAsk for confirmation
kDo not overwrite
TFiles from a file
vVerbose

Permissions

CommandDescriptionSwitchesSwitch Description
chmod octal fileChange permissions of a file4Read (r)
2Write (w)
1Execute (x)
chmod 777rwx for everyone
chmod 755rw for the owner, rx for group world

Calculating the number for permissions in chmod is done by adding the numbers for the permission you want granted. For example if you wanted to give read, write and execute permissions, you would add 4+2+1 = 7 (refer to the table above for which numbers relate to which permission). The 3 numbers in the chmod permission is broken up into the first number being the owners permissions, followed by the groups permissions and finally the publics permissions. 

Other Useful Commands

CommandDescription
grep pattern filesSearch in files for a pattern
grep -r pattern dirSearch for pattern recursively in dir
locate fileFind all instances of a file
whereis appShow possible locations of app
man commandShow manual page for a command

SUBSCRIBE FOR NEW POST ALERTS

Subscribe to be the first to know when we publish a new article!
List Subscriptions(Required)

POPULAR POSTS

Scroll to Top