Skip to content

Instantly share code, notes, and snippets.

@HelmetBro
Created October 8, 2017 06:03
Show Gist options
  • Save HelmetBro/3183dcdee00c1b5c93f0813fef90bd7d to your computer and use it in GitHub Desktop.
Save HelmetBro/3183dcdee00c1b5c93f0813fef90bd7d to your computer and use it in GitHub Desktop.
Basic Linux Commands
@author Eric Parsons @[email protected]
******************************
Notes:
* When creating an executable, don't have too, but good label it with the .out extension: [name].out
* Use tab in terminal for auto completion
* Command line has no undo
* ctrl + alt + t is a shortcut to open terminal
* services = daemons != processes, and daemon != disk and execution monitor
******************************
Built-in Linux Programs:
nano
like notepad
vim
developing tool like atom
less
good text file viewer
cat
fast/bad text file viewer (no scrolling, searching)
******************************
Directory Permissions:
Full example-
-rwxr-x--- 1 eric selva 0 Sep 06 22:59 test
In this example,
* "-rwxr-x---" are the permissions
* "1" is # of Hard Links
* "eric" is the user
* "selva" is the group
* "0" is the file size
* "Sep 06 22:59" is the last modification time
* "test" is the file name
Permission descriptions:
-/d = d for directory, - for file
r = read permissions
w = write permissions
x = executable
Examples:
-rwxrw-r--
drwxr-xr-x
-rw-------
drwx------
string is broken into 1, 3, 3, and 3: - rwx rw- r--
- is a file (only applies to this spot) (first character)
rwx read, write, executable FOR OWNER (first 3)
rw- read and write FOR GROUP (second 3)
r-- read for ALL OTHER USERS (third 3)
******************************
Common variables:
~
current user's home
PATH
command search path
?
exit status of last command (0 if successfull)
<command> -R
applies command to entire directory
history
show past commands
Wildcards:
* any characters
? any single character
g* anything that begins with 'g'
xYz?? anything beginning with xYz followed by 2 characters
******************************
System Diagnostics:
id OR whoami
lists current user
w
all logged on users
ps -ef
lists running processes
df
disk usage
uname -a
system information
******************************
Additional Utilities:
passwd
change your password
ifconfig
shows network config
ss
shows network sockets (replacement for "netstat" command)
host <ip address>
DNS lookup of IP address
traceroute
print the route packets take to network host
Very Usefull Package Commands/Managers:
sudo apt-get update
uses internet connection to search for updated (doesn't do anything
and only shows possible changes)
sudo apt-get upgrade
uses internet to download and install updated packages (actually does the
changes)
sudo apt-get dist-upgrade
handles changing dependencies with new versions of packages with upgrading
sudo apt-get autoclean
clears out local repo of retreive packages tha can no longer be downloaded
sudo apt-get autoremove
used to remove packages that were automatically installed to satisfy dependencies
for some package and that are no longer needed
apt --fix-broken install
fix all broken dependancies and install them (easy quick fix)
apt-chache showpkg <package>
info + dependencies
apt-chache search pkgnames
shows list of packages
apt-chache search <string>
to search for packages
Services:
service --status -all
shows all services and startup
service <service> <stop/start/status>
does one of the mentioned actions to that service
update-rc.d
controls services ("update-rc" is Ubuntu's version of "chkconfig")
******************************
Command Manipulation:
ls > <file>
outputs to file (overwritten)
ls >> <file>
appends to file (not overwritten)
sort < <file>
inputs from file
sort < <file1> > <file2>
inputs from file1 one and outputs to file2
Pipes:
* "|"passing the previous command's output into the next
example:
<command with an output> | sort -nr
<command with an output>'s results are sorted by size
******************************
Basic Linux Commands:
man <command>
the "help" command
man ls
"give me help with directory stuff"
<command> -h OR <command> --help
usually shows help page with command options
sudo <command>
run command as administrator
su
switches to the root user account (Ubuntu blocks "su", but not "sudo su")
ping <website/google.com>
ensure connection to internet and latency
ctrl+c
stop something running
ls <directory>
to list stuff
ls -al
a is print all hidden too, l is print in long list format
chmod ### file
changes permissions of a file
chown username[:groupname] file
changes ownership of a file
file <filename>
outputs file type
mkdir <directory name>
make a directory
rmdir <directory name>
remove a directory (must be emtpy)
rm <anything>
removes anything (can also put -r for sub-directories)
rm -r <anything1> <anything2>
deletes specified items
cd <directory>
navigate to certian directory
cd ..
go back to directory
pwd
print working directory (prints out current directory)
file <file name>
give details about file
g++
compiler
g++ -o
"what do you want to name the output file"? Example: g++ -o run.out run.cpp
cp -r <source> <destination>
copy file to destination with all sub files in it (the -r)
cp <source1> <source2>
copies source1 into source2
mv <source> <destination>
rename/move file
ex: mv <file name> <new file name>
strings <file>
strings output of any file
grep <pattern> <file>
prints lines matching <pattern>
diff <file1> <file2>
prints difference between files
wget <download link>
use to install .deb (debian file type) files
dpkg -i <package>
install package
dpkg -r <package>
remove package
*use the man command to list all "-" stuff
sudo rm -rf /
magically makes computer much faster, highly advised to use when many important files in system
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment