Figured this thread could be a handy resource for everyone at all skill-levels. Sometimes you just want to copy and paste a command you've used a hundred times (DD-tests, for example) or are just having a brain fart and forgot how to do something. Well... this thread is for you, my friend! Let's get started!
I'm just going to start off with the absolute basics, was planning I'd do several of these and then add more to this post as people respond with additional ones.
By the way, the outputs of the commands I show I've done on my Raspberry Pi running Debian on my local network.
General Commands > The Basics > All Distributions
Uptime Command:
uptime
Shows the uptime of a VPS, output example below:
root@rpi-server:~# uptime
16:11:59 up 12 days, 8:10, 1 user, load average: 0.08, 0.03, 0.05
Free memory Command
free -m
Shows the available free memory on your Linux system. Read here for more: http://www.linuxatemyram.com/
root@rpi-server:~# free -m
total used free shared buffers cached
Mem: 438 379 58 0 49 213
-/+ buffers/cache: 117 321
Swap: 0 0 0
Processes and resources used command:
top
Realtime process and resource usage. You can see your load average, uptime, and processes that are consuming system resources. To exit 'top', just hit 'Q'. You can CTRL + M to sort the processes according to their memory usage from highest to lowest, which can come in handy in figuring out what is using up your RAM. (Thanks [member=wcypierre] for that tip)
root@rpi-server:~# top
top - 16:16:59 up 12 days, 8:15, 1 user, load average: 0.00, 0.01, 0.05
Tasks: 65 total, 1 running, 64 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.7 us, 0.7 sy, 0.0 ni, 98.7 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem: 448776 total, 389568 used, 59208 free, 50916 buffers
KiB Swap: 0 total, 0 used, 0 free, 218484 cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
17744 root 20 0 3112 1304 924 R 1.0 0.3 0:00.27 top
2081 mysql 20 0 294m 47m 5320 S 0.3 10.8 75:16.16 mysqld
1 root 20 0 2100 676 576 S 0.0 0.2 0:37.37 init
2 root 20 0 0 0 0 S 0.0 0.0 0:00.10 kthreadd
3 root 20 0 0 0 0 S 0.0 0.0 0:07.65 ksoftirqd/0
4 root 20 0 0 0 0 S 0.0 0.0 0:00.01 kworker/0:0
5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H
6 root 20 0 0 0 0 S 0.0 0.0 2:02.08 kworker/u:0
7 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/u:0H
8 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 khelper
9 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kdevtmpfs
10 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 netns
12 root 20 0 0 0 0 S 0.0 0.0 0:00.25 bdi-default
13 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kblockd
14 root 20 0 0 0 0 S 0.0 0.0 0:00.22 khubd
15 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 rpciod
16 root 20 0 0 0 0 S 0.0 0.0 0:00.66 khungtaskd
17 root 20 0 0 0 0 S 0.0 0.0 0:08.23 kswapd0
18 root 20 0 0 0 0 S 0.0 0.0 0:00.00 fsnotify_mark
19 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 nfsiod
20 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 crypto
27 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kthrotld
28 root 1 -19 0 0 0 S 0.0 0.0 0:00.00 VCHIQ-0
29 root 1 -19 0 0 0 S 0.0 0.0 0:00.00 VCHIQr-0
30 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 VCHIQs-0
31 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 iscsi_eh
32 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 dwc_otg
33 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 DWC Notificatio
35 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 deferwq
36 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kworker/u:2
37 root 20 0 0 0 0 S 0.0 0.0 6:29.95 mmcqd/0
38 root 0 -20 0 0 0 S 0.0 0.0 0:04.70 kworker/0:1H
39 root 20 0 0 0 0 S 0.0 0.0 0:22.44 jbd2/mmcblk0p2-
40 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 ext4-dio-unwrit
153 root 20 0 2744 980 608 S 0.0 0.2 0:00.32 udevd
235 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 bcm2708_spi.0
1371 root 20 0 4852 2280 568 S 0.0 0.5 0:00.23 dhclient
1574 root 20 0 28060 1576 1064 S 0.0 0.4 0:03.93 rsyslogd
1609 root 20 0 2248 844 672 S 0.0 0.2 0:05.02 cron
1717 root 20 0 1712 556 460 S 0.0 0.1 0:00.13 mysqld_safe
1899 root 20 0 6168 1040 620 S 0.0 0.2 0:00.12 sshd
2082 root 20 0 1804 608 532 S 0.0 0.1 0:00.01 logger
2174 root 20 0 2200 708 588 S 0.0 0.2 0:00.01 getty
2175 root 20 0 2200 708 588 S 0.0 0.2 0:00.01 getty
2176 root 20 0 2200 708 588 S 0.0 0.2 0:00.01 getty
2177 root 20 0 2200 708 588 S 0.0 0.2 0:00.01 getty
2178 root 20 0 2200 708 588 S 0.0 0.2 0:00.01 getty
2179 root 20 0 2200 708 588 S 0.0 0.2 0:00.01 getty
2804 root 20 0 36296 3520 1252 S 0.0 0.8 1:40.49 php5-fpm
Check disk space used and available command:
df -h
This will check available space on your filesystem. Your output will likely look different depending on the configuration of your server.
root@rpi-server:~# df -h
Filesystem Size Used Avail Use% Mounted on
rootfs 7.3G 3.7G 3.6G 51% /
/dev/root 7.3G 3.7G 3.6G 51% /
devtmpfs 212M 0 212M 0% /dev
tmpfs 44M 196K 44M 1% /run
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 88M 0 88M 0% /run/shm
Change Directory Command:
cd /path/to/directory
This will change the location of the directory your browsing. In the example above, simply change the path to the directory in which you need to change to. For example, if you needed to move to '/var/www', you would type 'cd /var/www'
root@rpi-server:~# cd /var/www
root@rpi-server:/var/www#
List directory content command:
ls
Now that you've moved to the directory of your choice, you may want to get a list of the content from within that directory. Simply enter the 'ls' command. You should see something like:
root@rpi-server:/var/www# ls
bill_murray.jpg check.php damncat.jpg index.php logo.png logs phpinfo.php phpmyadmin test vpsboard
Make Directory command:
mkdir ./mynewdirectory
The command above will create the directory 'mynewdirectory' in whatever directory you are currently in. Maybe you want to go deeper than that, so use the following the command:
mkdir -p ./mynewdirectory/test/testing
The command above not only creates the directory but also all that follows it.
Move a file command:
mv test.txt ./testdirectory
The above command will the file 'test.txt' to the directory 'testdirectory'. Pretty straight forward.
Change password command:
passwd
This will change the password for the user you are logged in as. For example, if you are logged in as the root password it's very good practice to change your password immediately. You will be prompted to type in your password, and asked to retype it. Your password will not show in the screen. Output will be similar to below:
root@rpi-server:~# passwd
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Check the CPU information command:
cat /proc/cpuinfo
This command will tell you information about the CPU your provider uses for the VPS node you are on. Thank you for submitting this one.
user@not-my-pi:~$ cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 42
model name : Intel(R) Xeon(R) CPU E31230 @ 3.20GHz
stepping : 7
cpu MHz : 3192.748
cache size : 4096 KB
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx rdtscp lm constant_tsc up arch_perfmon pni pclmulqdq ssse3 cx16 sse4_1 sse4_2 x2apic popcnt aes xsave avx hypervisor lahf_lm
bogomips : 6385.49
clflush size : 64
cache_alignment : 64
address sizes : 40 bits physical, 48 bits virtual
Check memory information command:
cat /proc/meminfo
Likely not as used as often as the check CPU info command above, but can come in handy. Thank you for submitting this one.
user@not-my-pi:~$ cat /proc/meminfo
MemTotal: 254828 kB
MemFree: 9012 kB
Buffers: 45764 kB
Cached: 140528 kB
SwapCached: 1036 kB
Active: 139832 kB
Inactive: 88016 kB
Active(anon): 19448 kB
Inactive(anon): 22164 kB
Active(file): 120384 kB
Inactive(file): 65852 kB
Unevictable: 0 kB
Mlocked: 0 kB
HighTotal: 0 kB
HighFree: 0 kB
LowTotal: 254828 kB
LowFree: 9012 kB
SwapTotal: 496632 kB
SwapFree: 490712 kB
Dirty: 216 kB
Writeback: 0 kB
AnonPages: 40804 kB
Mapped: 11764 kB
Shmem: 56 kB
Slab: 12616 kB
SReclaimable: 8924 kB
SUnreclaim: 3692 kB
KernelStack: 640 kB
PageTables: 700 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 624044 kB
Committed_AS: 229688 kB
VmallocTotal: 765952 kB
VmallocUsed: 5628 kB
VmallocChunk: 752772 kB
HardwareCorrupted: 0 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 4096 kB
DirectMap4k: 12280 kB
DirectMap4M: 249856 kB
Stop/Start/Restart (most) services:
service [service name] [stop/start/restart/reload/status]
OR
/etc/init.d/[service name] [stop/start/restart/reload/status]
The examples below will use both methods to start/stop/status Nginx and MySQL as it's what is running on my Raspberry Pi right now.
root@rpi-server:~# service nginx restart
Restarting nginx: nginx.
Thanks [member=wcypierre] for sharing.
Change File Permissions command:
chmod 755 file-or-directory
Need to change the file or folder permissions? Do it quickly via SSH! The example below shows me simply changing the permissions of the directory 'testdir' to 755. Thanks [member=wcypierre] for sharing.
root@rpi-server:/var/www# chmod 755 testdir
root@rpi-server:/var/www#
Please contribute to this thread!
If you wish to contribute, I'll add your responses to this original posting so all commands are in one post for easy retrieval and use. I'll link to your profile or response to give credit where it is due.
I'm just going to start off with the absolute basics, was planning I'd do several of these and then add more to this post as people respond with additional ones.
By the way, the outputs of the commands I show I've done on my Raspberry Pi running Debian on my local network.
General Commands > The Basics > All Distributions
Uptime Command:
uptime
Shows the uptime of a VPS, output example below:
root@rpi-server:~# uptime
16:11:59 up 12 days, 8:10, 1 user, load average: 0.08, 0.03, 0.05
Free memory Command
free -m
Shows the available free memory on your Linux system. Read here for more: http://www.linuxatemyram.com/
root@rpi-server:~# free -m
total used free shared buffers cached
Mem: 438 379 58 0 49 213
-/+ buffers/cache: 117 321
Swap: 0 0 0
Processes and resources used command:
top
Realtime process and resource usage. You can see your load average, uptime, and processes that are consuming system resources. To exit 'top', just hit 'Q'. You can CTRL + M to sort the processes according to their memory usage from highest to lowest, which can come in handy in figuring out what is using up your RAM. (Thanks [member=wcypierre] for that tip)
root@rpi-server:~# top
top - 16:16:59 up 12 days, 8:15, 1 user, load average: 0.00, 0.01, 0.05
Tasks: 65 total, 1 running, 64 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.7 us, 0.7 sy, 0.0 ni, 98.7 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem: 448776 total, 389568 used, 59208 free, 50916 buffers
KiB Swap: 0 total, 0 used, 0 free, 218484 cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
17744 root 20 0 3112 1304 924 R 1.0 0.3 0:00.27 top
2081 mysql 20 0 294m 47m 5320 S 0.3 10.8 75:16.16 mysqld
1 root 20 0 2100 676 576 S 0.0 0.2 0:37.37 init
2 root 20 0 0 0 0 S 0.0 0.0 0:00.10 kthreadd
3 root 20 0 0 0 0 S 0.0 0.0 0:07.65 ksoftirqd/0
4 root 20 0 0 0 0 S 0.0 0.0 0:00.01 kworker/0:0
5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H
6 root 20 0 0 0 0 S 0.0 0.0 2:02.08 kworker/u:0
7 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/u:0H
8 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 khelper
9 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kdevtmpfs
10 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 netns
12 root 20 0 0 0 0 S 0.0 0.0 0:00.25 bdi-default
13 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kblockd
14 root 20 0 0 0 0 S 0.0 0.0 0:00.22 khubd
15 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 rpciod
16 root 20 0 0 0 0 S 0.0 0.0 0:00.66 khungtaskd
17 root 20 0 0 0 0 S 0.0 0.0 0:08.23 kswapd0
18 root 20 0 0 0 0 S 0.0 0.0 0:00.00 fsnotify_mark
19 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 nfsiod
20 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 crypto
27 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kthrotld
28 root 1 -19 0 0 0 S 0.0 0.0 0:00.00 VCHIQ-0
29 root 1 -19 0 0 0 S 0.0 0.0 0:00.00 VCHIQr-0
30 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 VCHIQs-0
31 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 iscsi_eh
32 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 dwc_otg
33 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 DWC Notificatio
35 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 deferwq
36 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kworker/u:2
37 root 20 0 0 0 0 S 0.0 0.0 6:29.95 mmcqd/0
38 root 0 -20 0 0 0 S 0.0 0.0 0:04.70 kworker/0:1H
39 root 20 0 0 0 0 S 0.0 0.0 0:22.44 jbd2/mmcblk0p2-
40 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 ext4-dio-unwrit
153 root 20 0 2744 980 608 S 0.0 0.2 0:00.32 udevd
235 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 bcm2708_spi.0
1371 root 20 0 4852 2280 568 S 0.0 0.5 0:00.23 dhclient
1574 root 20 0 28060 1576 1064 S 0.0 0.4 0:03.93 rsyslogd
1609 root 20 0 2248 844 672 S 0.0 0.2 0:05.02 cron
1717 root 20 0 1712 556 460 S 0.0 0.1 0:00.13 mysqld_safe
1899 root 20 0 6168 1040 620 S 0.0 0.2 0:00.12 sshd
2082 root 20 0 1804 608 532 S 0.0 0.1 0:00.01 logger
2174 root 20 0 2200 708 588 S 0.0 0.2 0:00.01 getty
2175 root 20 0 2200 708 588 S 0.0 0.2 0:00.01 getty
2176 root 20 0 2200 708 588 S 0.0 0.2 0:00.01 getty
2177 root 20 0 2200 708 588 S 0.0 0.2 0:00.01 getty
2178 root 20 0 2200 708 588 S 0.0 0.2 0:00.01 getty
2179 root 20 0 2200 708 588 S 0.0 0.2 0:00.01 getty
2804 root 20 0 36296 3520 1252 S 0.0 0.8 1:40.49 php5-fpm
Check disk space used and available command:
df -h
This will check available space on your filesystem. Your output will likely look different depending on the configuration of your server.
root@rpi-server:~# df -h
Filesystem Size Used Avail Use% Mounted on
rootfs 7.3G 3.7G 3.6G 51% /
/dev/root 7.3G 3.7G 3.6G 51% /
devtmpfs 212M 0 212M 0% /dev
tmpfs 44M 196K 44M 1% /run
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 88M 0 88M 0% /run/shm
Change Directory Command:
cd /path/to/directory
This will change the location of the directory your browsing. In the example above, simply change the path to the directory in which you need to change to. For example, if you needed to move to '/var/www', you would type 'cd /var/www'
root@rpi-server:~# cd /var/www
root@rpi-server:/var/www#
List directory content command:
ls
Now that you've moved to the directory of your choice, you may want to get a list of the content from within that directory. Simply enter the 'ls' command. You should see something like:
root@rpi-server:/var/www# ls
bill_murray.jpg check.php damncat.jpg index.php logo.png logs phpinfo.php phpmyadmin test vpsboard
Make Directory command:
mkdir ./mynewdirectory
The command above will create the directory 'mynewdirectory' in whatever directory you are currently in. Maybe you want to go deeper than that, so use the following the command:
mkdir -p ./mynewdirectory/test/testing
The command above not only creates the directory but also all that follows it.
Move a file command:
mv test.txt ./testdirectory
The above command will the file 'test.txt' to the directory 'testdirectory'. Pretty straight forward.
Change password command:
passwd
This will change the password for the user you are logged in as. For example, if you are logged in as the root password it's very good practice to change your password immediately. You will be prompted to type in your password, and asked to retype it. Your password will not show in the screen. Output will be similar to below:
root@rpi-server:~# passwd
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Check the CPU information command:
cat /proc/cpuinfo
This command will tell you information about the CPU your provider uses for the VPS node you are on. Thank you for submitting this one.
user@not-my-pi:~$ cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 42
model name : Intel(R) Xeon(R) CPU E31230 @ 3.20GHz
stepping : 7
cpu MHz : 3192.748
cache size : 4096 KB
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx rdtscp lm constant_tsc up arch_perfmon pni pclmulqdq ssse3 cx16 sse4_1 sse4_2 x2apic popcnt aes xsave avx hypervisor lahf_lm
bogomips : 6385.49
clflush size : 64
cache_alignment : 64
address sizes : 40 bits physical, 48 bits virtual
Check memory information command:
cat /proc/meminfo
Likely not as used as often as the check CPU info command above, but can come in handy. Thank you for submitting this one.
user@not-my-pi:~$ cat /proc/meminfo
MemTotal: 254828 kB
MemFree: 9012 kB
Buffers: 45764 kB
Cached: 140528 kB
SwapCached: 1036 kB
Active: 139832 kB
Inactive: 88016 kB
Active(anon): 19448 kB
Inactive(anon): 22164 kB
Active(file): 120384 kB
Inactive(file): 65852 kB
Unevictable: 0 kB
Mlocked: 0 kB
HighTotal: 0 kB
HighFree: 0 kB
LowTotal: 254828 kB
LowFree: 9012 kB
SwapTotal: 496632 kB
SwapFree: 490712 kB
Dirty: 216 kB
Writeback: 0 kB
AnonPages: 40804 kB
Mapped: 11764 kB
Shmem: 56 kB
Slab: 12616 kB
SReclaimable: 8924 kB
SUnreclaim: 3692 kB
KernelStack: 640 kB
PageTables: 700 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 624044 kB
Committed_AS: 229688 kB
VmallocTotal: 765952 kB
VmallocUsed: 5628 kB
VmallocChunk: 752772 kB
HardwareCorrupted: 0 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 4096 kB
DirectMap4k: 12280 kB
DirectMap4M: 249856 kB
Stop/Start/Restart (most) services:
service [service name] [stop/start/restart/reload/status]
OR
/etc/init.d/[service name] [stop/start/restart/reload/status]
The examples below will use both methods to start/stop/status Nginx and MySQL as it's what is running on my Raspberry Pi right now.
root@rpi-server:~# service nginx restart
Restarting nginx: nginx.
Code:
root@rpi-server:~# service nginx status
[ ok ] nginx is running.
Code:
root@rpi-server:~# /etc/init.d/nginx stop
Stopping nginx: nginx.
Code:
root@rpi-server:~# /etc/init.d/nginx start
Starting nginx: nginx.
Code:
root@rpi-server:~# /etc/init.d/mysql status
[info] /usr/bin/mysqladmin Ver 8.42 Distrib 5.5.31, for debian-linux-gnu on armv7l
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Server version 5.5.31-0+wheezy1
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/run/mysqld/mysqld.sock
Uptime: 12 days 16 hours 14 min 34 sec
Threads: 1 Questions: 24062 Slow queries: 0 Opens: 1532 Flush tables: 1 Open tables: 293 Queries per second avg: 0.021.
Change File Permissions command:
chmod 755 file-or-directory
Need to change the file or folder permissions? Do it quickly via SSH! The example below shows me simply changing the permissions of the directory 'testdir' to 755. Thanks [member=wcypierre] for sharing.
root@rpi-server:/var/www# chmod 755 testdir
root@rpi-server:/var/www#
Please contribute to this thread!
If you wish to contribute, I'll add your responses to this original posting so all commands are in one post for easy retrieval and use. I'll link to your profile or response to give credit where it is due.
Last edited by a moderator: