· Linux sysad

Commands for a System Administrator Part 1

Commands for a System Administrator, Part 2 Commands for a System Administrator, Part 3

I have put together a list of the most ‘need to know’ commands for any Linux System Administration. Whether you are looking to move to Linux, just moved or thinking about moving. Here you’ll find what you need to know to get started.

1. ls

The ‘ls’ command, list the files in the directory you are currently in. You can add arguments to ls to change to out out, adding -l will make it one file per list, -a show hidden and -h show the file size in human readable format ie in Megabyte/Gigabyte.

[[email protected] test]# ls -lah
total 41M
drwxr-xr-x 2 root root 4.0K Feb 26 21:05 .
drwxr-xr-x. 4 root root 4.0K Feb 26 20:52 ..
-rw-r–r– 1 root root 2.0M Feb 26 21:05 file.1
-rw-r–r– 1 root root 2.0M Feb 26 21:05 file.2
-rw-r–r– 1 root root 2.0M Feb 26 21:05 file.3
-rw-r–r– 1 root root 2.0M Feb 26 21:05 file.4
-rw-r–r– 1 root root 2.0M Feb 26 21:05 file.5

2. md5sum

Personally, I think md5sum is one of the most important commands you can use, you can use them to ensure that file you downloaded is the file that is expected (assuming the owner tells you the sum). I’ll refer you wiki page for more information. If you have a file with md5sums you can run ‘md5sum -c {file-of-sums}

    [[email protected] test]# md5sum file.*
    b2d1236c286a3c0704224fe4105eca49 file.1
    b2d1236c286a3c0704224fe4105eca49 file.2
    b2d1236c286a3c0704224fe4105eca49 file.3
    b2d1236c286a3c0704224fe4105eca49 file.4
    b2d1236c286a3c0704224fe4105eca49 file.5

3. dd

dd is used to convert and copy files, mostly used to create bogus files to test disk performance or to copy a whole disk to another disk.

    [[email protected] test]# dd if=/dev/zero of=file.random bs=10M count=1
    1+0 records in
    1+0 records out
    10485760 bytes (10 MB) copied, 0.0155453 s, 675 MB/s
    [[email protected] test]# ls -h file.random
    [[email protected] test]# ls -lah file.random
    -rw-r–r– 1 root root 10M Feb 26 21:24 file.random

4. uname

uname is to gather some system information, mainly used to get the running kernel version and the system architecture, it also has other information

    [[email protected] test]# uname -a
    Linux nginx.mylinux.uk 2.6.32-504.3.3.el6.x86_64 #1 SMP Wed Dec 17 01:55:02 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux 

5. history

History, is self explanatory, running history will show a list of previously run commands of the user you are logged in as.

    [[email protected] test]# history
    1077 ls
    1078 for i in {1..20}; do dd if=/dev/zero of=file.$i bs=1M count=2 ; done
    1079 ls -lah
    1080 md5sum file.* > file.md5sum
    1081 md5sum -c file.md5sum
    1082 dd if=/dev/zero of=file.random bs=10M count=1
    1083 ls -h file.random
    1084 uname -a
    1085 history

6. mkdir

mkdir is used to ‘make directory’. Run this and 1 argument and it’ll make that argument into a directory inside where you are. You can specify a full path ie ‘mkdir /home/user/dir1/dir2′ this will home work if /home/user/dir1 already exists, unless you use the -p and it will make parent directories as needed.

    [[email protected] test]# mkdir –help
    Usage: mkdir [OPTION]… DIRECTORY…
    Create the DIRECTORY(ies), if they do not already exist.

    Mandatory arguments to long options are mandatory for short options too.
    -m, –mode=MODE set file mode (as in chmod), not a=rwx – umask
    -p, –parents no error if existing, make parent directories as needed
    -v, –verbose print a message for each created directory
    -Z, –context=CTX set the SELinux security context of each created directory to CTX

8. touch

touch is used to change the timestamp of a files, but a very useful feature is that it will create a file, if that file does not exist. touch is used, probably, more for this than changing timestamps.

    [[email protected] test]# touch test
    [[email protected] test]# ls -lah test
    -rw-r–r– 1 root root 0 Feb 26 21:58 test
    [[email protected] test]# rm -f test
    [[email protected] test]# 

9. chmod, chown

chmod, Change mode. Is essentially changing the permissions of a file, or directory. Permissions can be set for a single file/directory or you can change the permissions recursively. See the ‘rwxrwxrwx’ that is the ‘777’ part. 7 is the sum of the number for Read, Write and Execute, so 777 is bad because everyone can do anything to the file.

    [[email protected] test]# chmod 777 file.1
    [[email protected] test]# ls -lah file.1
    -rwxrwxrwx 1 root root 2.0M Feb 26 21:40 file.1

10. yum

Yellowdog update modified. Yum is an RPM package manager used to install, update and remove packages, yum also automatically resolved dependency issues and downloads them too. Packages are obtained from the installed repositories. See the man page for more information. Yum will soon be deprecated with dnf being the drop-in replacement, so all yum knowledge ‘should’ carry over to dnf

    [[email protected] test]# yum install package

11. tar

Tar is used to save files together into one, usually compressed file. Similar to zip. Compressions type can be set but remember, that high compression means longer times. -j bzip2 compression, -c is compress, -v is verbose is -f use archive file or device ARCHIVE

    [[email protected] test]# tar -jcvf files.bzp2 file.1 file.2 file.11 file.12
    [[email protected] test]# ls -lah files.bzp2
    -rw-r–r– 1 root root 164 Feb 26 22:14 files.bzp2

12. date

Not a lot to the date command, you can read and set the system date and time. Its always useful to time stamp files and it can be great in scripts.

    [[email protected] test]# date
    Thu Feb 26 22:19:51 UTC 2015
    [[email protected] test]# cp file1 file1-$(date +%Y-%m-%d)
    [[email protected] test]# ls
    file1 file1-2015-03-06

13. cat

Used mostly for read the contents of a files but also concatenate files.

    [[email protected] test]# cat file.md5sum
    b2d1236c286a3c0704224fe4105eca49 file.1
    b2d1236c286a3c0704224fe4105eca49 file.10
    b2d1236c286a3c0704224fe4105eca49 file.11
    b2d1236c286a3c0704224fe4105eca49 file.12
    b2d1236c286a3c0704224fe4105eca49 file.13
    b2d1236c286a3c0704224fe4105eca49 file.14

14. cp

Copy files and directories, the syntax is cp {source} {destination}. I recommend reading the man page to familiarise yourself with it.

    [[email protected] test]# cp file.1 file.100
    [[email protected] test]# ls -lah file.1 file.100
    -rwxrwxrwx 1 root root 2.0M Feb 26 21:40 file.1
    -rwxr-xr-x 1 root root 2.0M Feb 26 22:23 file.100

15. mv

Similar to the above, except moving rather than copying, its moved the file or directory, syntax in the same as cp

    [[email protected] test]# mv file.2 file.200
    [[email protected] test]# ls -lah file.2 file.200
    ls: cannot access file.2: No such file or directory
    -rw-r–r– 1 root root 2.0M Feb 26 21:40 file.200

16. pwd

Print working directory, it literally just shows you were you are on the server. Not much to the command, can be useful for to copy/paste the directory into a ticket or email.

    [[email protected] test]# pwd

Thanks for reading, I hope it helps! Part two will be out soon. Edit: Part 2 is here

  • LinkedIn
  • Tumblr
  • Reddit

Aaron Mehar

Berkshire, UK