Anda di halaman 1dari 3

Linux Commands

Ubuntu 10.04
Basic Linux Tasks:
Sudo is used before a command. It acts like "run as administrator" in Windows
Man pages are reference pages for commands and programs
Example of usage: man ping
q quits man pages
The tasksel command installs numerous programs at one time to create a server (L
AMP or such)
Example: sudo tasksel
Apt-get Installs, Removes or Updates Software
Install: sudo apt-get install xxx
Uninstall: sudo apt-get remove xxx
Update: Sudo apt-get upgrade
Restart Services
Example: sudo /etc/init.d/xxx (restart start stop)
Top is like "Task Manager" in Windows
Example: sudo top
K to kill a process
H for help
Basic navigation
To change to another directory use the cd command
Example: cd /etc/var/www (changes to web root folder)
Linux is literal
Capitalization matters!!!
Final Thoughts
To Logout just use the exit command
Resources
Vim For Editing Files:
Introduction
No .txt -- no file association
Starting VIM
Sudo vim XXX (opens a file, or creates file)
Sudo -- sometimes you need, sometimes not... if you use it it will always work..
.
To change ownership of a file (Sometimes needed to edit .ini and configuration f
iles)- Sudo chown user file
Editing and Navigating
a = insert, esc = exit insert
:/ = find (use wildcards)
:/? = Find backward
n = next
Exiting and Saving
:q = quit
:q! = quit no save
:wq = save and quit
:e = open file
:w = save as
Final Thoughts...
Very complicated... Lots of options... these are good enough to start with....
Resources
Navigation:
Changing Directories
CD
ls --l or ls -m
Searching = sudo find -iname XXX (You can use Wild Cards)
-iname arguement is to make the search case insensitive

Make /remove/ move directories


sudo mkdir folder
sudo rm folder (sudo rm folder --r for directory and trees)
sudo mv file/folder -- moves/ renames
sudo cp souce destination- copy (add --r for directories)
Mounting Dives
Basic Process = Create Directory -- List Attached Drives -- Link Directory to Dr
ive
Make folder to be mounted -- sudo mkdir /mnt/folder (Create folder in /mnt direc
tory for easier administration)
To list drives attached to computer -- sudo fdisk --l
To mount a drive -- sudo mount drive folder
Mount cdrom -- sudo mount /dev/cdrom /folder
To unmount drive -- sudo umount drive
Use /mnt/subfolder for exclusions later
Users and Groups:
Users
Add User = sudo adduser username
Change User password = sudo passwd username
Delete User = sudo userdel username
Edit Users Configuration File = sudo vim /etc/passwd (shows usernames, names of
users, home directories)
Groups
Sudo groupadd groupname
Sudo groupdel groupname
Sudo vim /etc/group (shows groups and users)
Permissions
Numbers = owner/group/everyone else
4 = read, 2 = write, 1 = execute
To Chanege Permissions of a File or Folder = sudo chmod 777 file/folder (-R for
recursive)
Changing Ownership
To Change User Ownership = sudo chown -R username file/folder
To Change Group Ownership =sudo chgrp --R groupname file/folder
-R for Recursive for Folders
Network Configuration:
Basic Tasks
To Show Current IP Addresses and Network Configuration = sudo ifconfi
To Release and Renew IP Address = sudo dhclient
To Restart the Networking Service = sudo /etc/init.d/networking restart
Always Restart the Networking Service After Changing Network Configurations
Network Config file
To Edit the Network Adapter Configurations = sudo vim /etc/network/interfaces
auto eth0 = Auto Negotiate Speed for Ethernet Card 0
iface eth0 inet static /dhcp = Ethernet Card 0 Either Static or DHCP Address. If
DHCP Don't Go Further.
address 192.168.1.100 = Static IP Address
netmask 255.255.255.0 = Subnet Mssk
network 192.168.1.0 = Network (Generally Your IP Address Siply with a 0 in the L
ast Octet))
broadcast 192.168.1.255 = Broadcast Address (The Last Address in Your Subnet. Ge
nerally Your IP Address with a 255 in the Last Octet.)
gateway 192.168.1.1 = Default Gateway. Generally Your ISP Modem or Router
To Edit the DNS Resolution File = sudo vim /etc/resolv.conf
To See Current Hostname = sudo /bin/hostname
To Change Hostname = sudo /bin/hostname newhostname
Ping
To Determine if You Can See an IP Address = ping IP Address

To Determine DNS is Working = ping domainname


UFW firewall
To Chaneg Default Handling of Ports When UFW is Enabled = sudo ufw default allow
/deny
To Turn UFW on or Off = sudo ufw enable/disable
To Open or Close Ports for Everyone = sudo ufw allow/deny port#
To Delete a UFW Rule = sudo ufw delete allow/deny port#
To Allow Access to All Ports from a Specific IP Address = sudo ufw allow from IP
Address
To Allow Access to a Specific Port from a Specific IP Address = sudo ufw allow f
rom IP Address to any port port#
Final Thoughts
Drivers Should Work Out of the Box...
Wireless Networking is Its own Topic
SSH and FTP:
SSH -- Secure Shell
Install SSH on Server = sudo apt-get install ssh
SSH Requires Port 22
Use a Terminal Emulator to Connect to the Server (PuTTy)
FTP -- File Transfer Protocol
Install FTP Server = sudo apt-get install vsftpd
Edit vsftpd Configuration Files = sudo vim /etc/vsftpd.conf
Uncoment #local_enable=YES to Allow Local Users to Login
Uncomment #write_enable=YES to Allow File Uploads
To Restart vsftpd Service = sudo service vsftpd restart
Use an FTP Client to Connect to FTP Server (FileZilla)
Resources
Backup:
Backup Using TAR
Backup = sudo tar --cvpzf backup.taz.gz --exclude/=directory (recursive) PATH
--c = create new file (overwrites old file)
--v = verbose
--p = preserve permissions
--z = compress
--f = filename (very important)
--exclude=DIRCECTORY is Recursive
Naming Files with time = filename-$(date +%F-%T)
Recover Files from a TAR File
Recover = sudo tar --xvpzf FILE --C /DIRECTORY
Capital -C = change to directory
-x = extract
Cron Jobs
To Edit the Crontab File = sudo cron --e (first time it will ask you your defaul
t editor)
Format = minute (0-59), hour (0-23, 0 = midnight), day (1-31), month (1-12), wee
kday (0-6, 0 = Sunday), command
* Wildcard for Every Minute/Day/Hour/Month?Day of Week
Example to Backup Entire Server for 1am Every Morning = 0 1 * * * sudo tar -cvpz
f /backup.tar.gz --exclude=/mnt /

Anda mungkin juga menyukai