Difference between revisions of "Miscellaneous Linux Commands"
Line 131: | Line 131: | ||
The actual working command to close the CD-ROM tray after I've inserted a disk into the tray on my server is: | The actual working command to close the CD-ROM tray after I've inserted a disk into the tray on my server is: | ||
<pre style="color:blue">$ eject -t /dev/sr0 </pre> | <pre style="color:blue">$ eject -t /dev/sr0 </pre> | ||
+ | <br /><br /> | ||
+ | <h4>USB Devices</h4> | ||
+ | <br /> | ||
+ | To determine which device your USB thumb drive is connect to, use the "dmesg" command again, as follows: | ||
+ | <pre style="color:blue"> | ||
+ | # dmesg | grep -i Attached SCSI | ||
+ | </pre> | ||
+ | <br /><br /> | ||
+ | To manually check & fix a USB file system, use this example(As the root super user): | ||
+ | <pre style="color:blue"> | ||
+ | # fsck.fat -atvV /dev/sde1 | ||
+ | fsck.fat 3.0.25 (2014-01-17) | ||
+ | fsck.fat 3.0.25 (2014-01-17) | ||
+ | Checking we can access the last sector of the filesystem | ||
+ | 0x41: Dirty bit is set. Fs was not properly unmounted and some data may be corrupt. | ||
+ | Automatically removing dirty bit. | ||
+ | Boot sector contents: | ||
+ | System ID "MSDOS5.0" | ||
+ | Media byte 0xf8 (hard disk) | ||
+ | 512 bytes per logical sector | ||
+ | 16384 bytes per cluster | ||
+ | 10144 reserved sectors | ||
+ | First FAT starts at byte 5193728 (sector 10144) | ||
+ | 2 FATs, 32 bit entries | ||
+ | 3784704 bytes per FAT (= 7392 sectors) | ||
+ | Root directory start at cluster 2 (arbitrary size) | ||
+ | Data area starts at byte 12763136 (sector 24928) | ||
+ | 945313 data clusters (15488008192 bytes) | ||
+ | 63 sectors/track, 128 heads | ||
+ | 8064 hidden sectors | ||
+ | 30274944 sectors total | ||
+ | Starting check/repair pass. | ||
+ | Checking for bad clusters. | ||
+ | Reclaiming unconnected clusters. | ||
+ | Checking free cluster summary. | ||
+ | Starting verification pass. | ||
+ | Checking for unused clusters. | ||
+ | Performing changes. | ||
+ | /dev/sde1: 30111 files, 611080/945313 clusters | ||
+ | </pre> | ||
<br /><br /> | <br /><br /> |
Revision as of 23:18, 31 March 2015
Shell Commands
Display all network interface names on any Linux system from the shell:
/sbin/ifconfig | grep BROADCAST | cut -d " " -f1 | sed 's/.$//'
Most Linux machines will only display one network interface, such as shown on my Slackware 14.1 Virtual Machine Server:
eth0
Other systems may have more than one, such as those with virtual machine software or with more than one physical NIC.
Also, some systems use non-standared network interface names, other than the usual eth0.
Here are some samples of those types of systems. In these examples, the first network interface name is the main one used, and the following ones are used for the virtual machine software.
Sample output from my Fedora 20 (Heisenbug) VirtualBox server:
em1 virbr0
And here is a sample output from my Fedora 17 (Beefy Miracle) laptop running VMWare:
p5p1 vmnet1 vmnet8
The "ps" Process Command Syntax
To show all executing processes:
$ ps ax
To show all processed running by a specific user(This example shows all processes running by the Apache WebServer):
$ ps -U apache
Miscellaneous CD/DVD & USB Command Line Commands
To show all mounted drives, both the "mount" and "df" commands are useful and helful, as seen here(Example using one of my servers):
$ mount proc on /proc type proc (rw,nosuid,nodev,noexec,relatime) sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel) devtmpfs on /dev type devtmpfs (rw,nosuid,seclabel,size=8104892k,nr_inodes=2026223,mode=755) securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime) tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,seclabel) devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,seclabel,gid=5,mode=620,ptmxmode=000) tmpfs on /run type tmpfs (rw,nosuid,nodev,seclabel,mode=755) tmpfs on /sys/fs/cgroup type tmpfs (rw,nosuid,nodev,noexec,seclabel,mode=755) cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd) pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime) cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset) cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct,cpu) cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory) cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices) cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer) cgroup on /sys/fs/cgroup/net_cls type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls) cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio) cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event) cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb) /dev/mapper/fedora-root on / type ext4 (rw,relatime,seclabel,data=ordered) selinuxfs on /sys/fs/selinux type selinuxfs (rw,relatime) systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=41,pgrp=1,timeout=300,minproto=5,maxproto=5,direct) mqueue on /dev/mqueue type mqueue (rw,relatime,seclabel) tmpfs on /tmp type tmpfs (rw,seclabel) configfs on /sys/kernel/config type configfs (rw,relatime) debugfs on /sys/kernel/debug type debugfs (rw,relatime) hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,seclabel) sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime) sunrpc on /proc/fs/nfsd type nfsd (rw,relatime) /dev/md126p1 on /boot type ext4 (rw,relatime,seclabel,data=ordered) /dev/mapper/data-home on /home type ext4 (rw,relatime,seclabel,data=ordered) fusectl on /sys/fs/fuse/connections type fusectl (rw,relatime) gvfsd-fuse on /run/user/1000/gvfs type fuse.gvfsd-fuse (rw,nosuid,nodev,relatime,user_id=1000,group_id=1000)
Output of the "df" command on one of my servers:
(I added the -h switch to show sizes in "Human Readable" format, meaning it shows an M or G for Megabytes & Gigabytes)
$ df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/fedora-root 58G 47G 8.0G 86% / devtmpfs 7.8G 0 7.8G 0% /dev tmpfs 7.8G 88M 7.7G 2% /dev/shm tmpfs 7.8G 1.2M 7.8G 1% /run tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup tmpfs 7.8G 92M 7.7G 2% /tmp /dev/mapper/extra-extra1 197G 93G 95G 50% /mnt/extra1 /dev/mapper/more-morespace1 586G 371G 186G 67% /mnt/more1 /dev/md126p1 969M 116M 787M 13% /boot /dev/mapper/fedora-save 197G 60M 187G 1% /mnt/save /dev/mapper/data-vms2 296G 180G 102G 64% /mnt/vms2 /dev/mapper/backup-vms 197G 184G 3.7G 99% /mnt/vms /dev/mapper/archive-archive1 501G 399G 77G 84% /mnt/archive /dev/mapper/data-data1 99G 79G 15G 84% /mnt/data1 /dev/mapper/data-home 197G 172G 16G 92% /home
- VERY IMPORTANT INFO!!! *****
In order to "SAFELY" remove a CD, DVD, USB, Removable Hard Drive, or any type of removable media or drive,
YOU MUST FIRST UNMOUNT the removable media or drive, and also possibly detatch and/or eject the media or drive.
Here are the command line commands to perform these functions:
The first step applies to all situations and types of drives or medium, which is to "UNMOUNT" the drive, using the "umount" command.
NOTICE the "N" is dropped in the actual unmount command, so "umount" is NOT a typo!
For example, here is how to unount a mounted CD ROM disk inserted into the drive. Also, instead of pushing the little push button on the front of CD & DVD drives, I prefer to use command line commands to both open and close the drive tray, if it is the type that has a tray that opens/ejects to insert a disk.
To open and close the CD/DVD drive tray, use the eject command as follows:
$ eject
This should open the disk tray. If you have more than one CD/DVD ROM drive, you need to specify the device name of the unit you want to use, as shown here:
$ eject /dev/sdb
or
$ eject /dev/sdc
The actual device name depends on how it is installed in your computer. To get an idea of the actual device name your computer uses for it's
CD/DVD ROM drives, I like to use the "dmesg" command, as show here:
$ dmesg | grep -i cd-rom [ 0.666858] scsi 4:0:0:0: CD-ROM ASUS DRW-24F1ST a 1.00 PQ: 0 ANSI: 5 [ 0.670145] cdrom: Uniform CD-ROM driver Revision: 3.20 [ 0.670287] sr 4:0:0:0: Attached scsi CD-ROM sr0
As you can see from above, the CD/DVD ROM burner I have is an Asus DRW-24F1ST, attached to scsi CD-ROM device "sr0".
This is the important device name: sr0 which you can then use to eject/open and close the CD-ROM drive tray.
FYI, "sr0" stands for "SCSI Recorder 0", in case you were wondering...
So, the actual working example on my server to open/eject the tray is:
$ eject /dev/sr0
The actual working command to close the CD-ROM tray after I've inserted a disk into the tray on my server is:
$ eject -t /dev/sr0
USB Devices
To determine which device your USB thumb drive is connect to, use the "dmesg" command again, as follows:
# dmesg | grep -i Attached SCSI
To manually check & fix a USB file system, use this example(As the root super user):
# fsck.fat -atvV /dev/sde1 fsck.fat 3.0.25 (2014-01-17) fsck.fat 3.0.25 (2014-01-17) Checking we can access the last sector of the filesystem 0x41: Dirty bit is set. Fs was not properly unmounted and some data may be corrupt. Automatically removing dirty bit. Boot sector contents: System ID "MSDOS5.0" Media byte 0xf8 (hard disk) 512 bytes per logical sector 16384 bytes per cluster 10144 reserved sectors First FAT starts at byte 5193728 (sector 10144) 2 FATs, 32 bit entries 3784704 bytes per FAT (= 7392 sectors) Root directory start at cluster 2 (arbitrary size) Data area starts at byte 12763136 (sector 24928) 945313 data clusters (15488008192 bytes) 63 sectors/track, 128 heads 8064 hidden sectors 30274944 sectors total Starting check/repair pass. Checking for bad clusters. Reclaiming unconnected clusters. Checking free cluster summary. Starting verification pass. Checking for unused clusters. Performing changes. /dev/sde1: 30111 files, 611080/945313 clusters