So we’ve covered a few basics of a Linux host in Part I–
- The File System
- Users, groups
- Basic Commands with basic arguments
- And file and directory permissions
Hopefully, what I share next will build on the first post and enhance your knowledge as you move forward with Linux.
Reading the contents of a directory, gathering information on files and locating files are some of the most common tasks a DBA will perform as they work on a server. Many of the following commands require you to “pipe” a second command onto the first. This is done by joining the commands with a “|”, (pipe).
We’ll start out by gathering size information about your Linux server and directories.
df -h will offer you information about the host, connected luns in a format that’s easier to read than if you left the “-h” argument off.
df -h Output Example: $ df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_linuxsource-lv_root 14G 3.0G 11G 23% / tmpfs 3.9G 0 3.9G 0% /dev/shm /dev/xvda1 477M 130M 322M 29% /boot /dev/xvdf 30G 7.0G 21G 25% /u01 /dev/xvdg 20G 4.1G 15G 22% /u02
You can see each of the LUNS, including all information about those. The far left file system column is the actual lun name vs. the far right that shows the mount name. /u01 is a common directory for installations and /u02 is a common directory for datafiles. Don’t be surprised that Linux design comes with less logical or physical luns than Windows. This is quite common.
You can see the storage allocation, amount used and space available for each.
You can also look at file storage usage at the directory level to capture the immediate directory values, (and it will display every directory in the destination that you are running the command in, so in our example, I’ll add a directory to the argument):
du -h Output Example: $ du -h /u02/oracle/scripts 508K /u02/oracle/scripts
This is done with the list command, (ls). There are a number of arguments that are used, but the following I think are the most important ones for a DBA to know when working on Linux.
Last post we discussed the importance of viewing hidden files, (such as those beginning with a “.”)
ls -la Output Example: $ ls -la total 2712 drwxr-xr-x. 10 delphix oinstall 4096 Oct 18 19:28 . drwxr-xr-x. 7 root root 4096 May 13 2016 .. lrwxrwxrwx 1 delphix oinstall 24 Jan 13 2017 11g.env -> /u02/app/content/11g.env -rwxr-xr-x 1 delphix oinstall 648 Jul 6 2015 aseTail -rwxr-xr-x 1 delphix oinstall 509 Jul 6 2015 aseTest -rwxr-xr-x 1 delphix oinstall 509 Jul 6 2015 ase_test.sh -rw-r--r-- 1 delphix oinstall 470 Jan 13 2017 .bash_profile -rw-r--r-- 1 delphix oinstall 292 Dec 29 2014 .bashrc
Without the “a” argument at the end, you won’t be able to view the .bash_profile or any unique .profile settings that a user has configured.
In the example list above, note that not only do we see the immediate folder, (‘.’) but the folder above the one we’re in, (‘..’) There’s also an alias for 11g.env that points to the full directory path and then files starting with a ‘.’, (.bash_profile and .bashrc) These are your configuration files for the user that are loaded whenever the user logs in. All profile settings and such are contained in these files.
Referring back to our previous post, we can view the permissions for each of the files listed. The owner, the group and other.
Using the aseTail file, we can see the permissions for each are: -rwxr-xr-x
- Owner has Read, (r) write, (w) and execute, (x) = 7
- Group has Read, (r) and execute, (x) = 5
- Other has Read, (r) and execute, (x) = 5
If we were to assign numerical values to the permissions, aseTail = 755
We could also display the files from the most recent, descending:
ls -ltr Output Example: $ ls -ltr total 504 -rwxrwxr-x 1 oracle oinstall 576 Sep 16 2014 startup.sh -rwxrwxr-x 1 oracle oinstall 442 Jan 14 2015 shutdown.sh -rwxrwxr-- 1 oracle oinstall 505876 Jun 23 2015 startup_shutdown.log
The files are sorted with the oldest file at the top, (Sept. 16 2014) to the most recent, (Jun 23 2015).
To sort files by size, largest in bytes, at the bottom:
ls -lSr Output Example: ls -lSr total 504 -rwxrwxr-x 1 oracle oinstall 442 Jan 14 2015 shutdown.sh -rwxrwxr-x 1 oracle oinstall 576 Sep 16 2014 startup.sh -rwxrwxr-- 1 oracle oinstall 505876 Jun 23 2015 startup_shutdown.log
You can also use the “|” to change how the data is displayed and add a second command after the argument or “pipe”:
ls -lSr | less
Output Example: total 504 -rwxrwxr-x 1 oracle oinstall 442 Jan 14 2015 shutdown.sh -rwxrwxr-x 1 oracle oinstall 576 Sep 16 2014 startup.sh -rwxrwxr-- 1 oracle oinstall 505876 Jun 23 2015 startup_shutdown.log (END) To exit, hit "q"uit
Searching for Files
OK, we’re ready for commands that are more than two letters long! The find command can locate files on your Linux host.
find <filename> find *<search word>* Output Example: $ find get* get-pip.py
Search for a file in a directory, (performed on my Mac, so don’t think I’m storing Powerpoint files one of my Linux hosts… :))
find <directory>/*<search>* Output Example: find /Users/kellyn/Desktop/*.pptx /Users/kellyn/Desktop/Containers_DevOps_Kgorman.pptx /Users/kellyn/Desktop/DBA_devops_dataops.pptx /Users/kellyn/Desktop/OTW_indexes_mssql_ora.pptx /Users/kellyn/Desktop/triad_evang.pptx
All files that match my search criteria and reside on the Desktop folder are displayed with this search.
Last but not least, there are times you need to know what installation patch is being used. In our example, lets say we need to know which of two java installations are being used. You can use the “which” command to do this:
which <program name> Output Example: $ which java /usr/bin/java
If you want to see how many versions of an application is installed, you can use the -a argument:
which -a <program name> Output Example: which -a oracle /u01/app/oracle/product/22.214.171.124/db_1/bin/oracle /u01/app/oracle/product/12.2/db_home1/bin/oracle
This gives you a good start on navigation, searching and locating. Next we’ll get into VI/VIM, (good ol’school standards that every DBA should know when editing files!)
Also published on Medium.