Posts Tagged ‘Linux’

touch: cannot touch file No such file or directory  Alerting On Read Only Filesystem Errors

November 25th, 2023, posted in Linux OS

Troubleshooting filesystem issues can be a complicated task, and it is made almost impossible if the system is unable to create logs or if you’re unable to access the logs.

There are few instances in which this might occur. This article will focus on a specific instance: when the file system is remounted as read-only.

Read-only Filesystem Issue / Errors

By default, Linux will mount the filesystems as read+write, but some times, due to failures, they can be automatically remounted as read-only. When that happens, well, you can only read your files, not write to them.

There a couple of different reasons why an issue like this might occur. One of the more common reasons is when the system boots after a crash (or loses power) where it is unable to shutdown correctly. The system will try to auto correct during boot, but if it is unable to do so, it will mount in read-only mode.

A real-world example might be if your hosting provider has an infrastructure failure. Your servers come online, but all of a sudden the file-system is in a read-only mode.

Working with Read-only Filesystem Logs

Building on the above scenario, let’s assume your server filesystem is in read-only mode. What do you do? How do you identify that is what is happening?

First, keep an eye out for “cannot create file: read-only file system” warnings in terminal. Such an example might occur if you try to do something like this:

root@test-server:~# tail /va-bash: cannot create temp file for here-document: Read-only file system
-bash: cannot create temp file for here-document: Read-only file system

This is a good indicator that a problem exists. A good way to confirm is by trying to touch a file to see if works:

root@test-server:~# touch test
touch: cannot touch 'test': Read-only file system

If it does not allow you to create the file you know where the issue is, you’re likely working a read-only file system issue.

Anther way to test is using mount. You can type the command “mount” and the output will give you something like this: , you can confirm if the server is in read-only (ro) mode:

# mount
/dev/sda4 on / type ext4 (ro,relatime,data=ordered)

In the entry above you see the reference to ro which is the abbreviation for read-only.

Solving the issue can be as simple as rebooting the server, but if that does not work you will have to investigate further.


Last Command Examples For Linux And Unix

May 8th, 2022, posted in Solaris

How to find out last logins of users and times informations on Linux/Unix-like operating systems ?

You need to use the last command to show who has recently used the server and logged in and out date/time.


The last command reads listing of last logged in users from the system file called /var/log/wtmp or the file designated by the -f options.


To find out when a particular user last logged in to the Linux or Unix server.


The basic syntax is:

last [userNameHere] last [tty] last [options] [userNameHere]

If no options provided last command displays a list of all users logged in (and out) since /var/log/wtmp file was created. You can filter out results by supplying names of users and tty’s to show only those entries matching the username/tty.

last command examples

To find out who has recently logged in and out on your server, type:
$ last
Sample outputs:

root     pts/1       Tue Jan 28 05:59   still logged in   
root     pts/0       Tue Jan 28 04:08   still logged in   
root     pts/0       Sat Jan 25 06:33 - 08:55  (02:22)    
root     pts/1       Thu Jan 23 14:47 - 14:51  (00:03)    
root     pts/0       Thu Jan 23 13:02 - 14:51  (01:48)    
root     pts/0       Tue Jan  7 12:02 - 12:38  (00:35)    
wtmp begins Tue Jan  7 12:02:54 2014

You can specifies a file to search other than /var/log/wtmp using -f option. For example, search /nas/server/webserver/.log/wtmp:
$ last -f /nas/server/webserver/.log/wtmp
last -f /nas/server/webserver/.log/wtmp userNameHere

List all users last logged in/out time

last command searches back through the file /var/log/wtmp file and the output may go back to several months. Just use the less command or more command as follows to display output one screen at a time:
$ last | more
last | less

List a particular user last logged in

To find out when user vivek last logged in, type:
$ last vivek
$ last vivek | less
$ last vivek | grep 'Thu Jan 23'

Sample outputs:

Fig. 01 Displaying out when user vivek last logged in on server

Fig. 01 Displaying out when user vivek last logged in on server


SWAP size Adding While installing a Oracle Database 19c on Oracle Linux

January 30th, 2022, posted in Oracle, Solaris

SWAP size Adding While installing a Oracle Database 19c on Oracle Linux,SWAP size Adding,installing a Oracle Database 19c,Oracle Linux,Oracle,Linux

SWAP Size Adding  size while installing a Oracle Database 19c on Oracle Linux

Below is the error message I received while I was trying to install Oracle Database 19c on Oracle Linux 7.

PRVF-7573 : Sufficient swap size is not available on node

As per my error on the installer screen I needed 16GB of SWAP space where as my system has just 4GB. So I need to add a swap file for the installation to continue. 

Below steps will outline the steps for the same.

dd if=/dev/sdb of=/tmp/swap01 bs=1K count=16M
chmod 600 /tmp/swap01
mkswap /tmp/swap01
swapon /tmp/swap01

Make sure the bs (*) count is equal to your required SWAP space. Also, the /dev/sdb has enough storage as needed


Using VI Editor (Visual Editor)

January 17th, 2021, posted in Linux OS, Solaris

VI Editor (Visual Editor)

You must be familiar with notepad in windows which is used to edit a file. Like-wise we have VI editor in UNIX, LINUX & SOLARIS OS used widely for editing files.
However, Unlike notepad it is little tricky to use. I wish the VI editor would have been developed by Bill gates rather than Bill Joy.
Anyways, guys we don’t have any other option rather than getting aware of all these commands so that we become proficient in working with the VI Editor.

Understanding different modes in VI Editor:
There are three different modes in VI editors:
1. Command Mode
2. Insert/input Mode
3. EX mode

By default when you will open the VI editor, it will be in command mode. In the following sections we will see:
1. How to switch from one mode to another?
2. What are the different VI Commands that we can use in these modes.

Command Mode : 
This is default mode of the VI editor. In this mode we can delete, change, copy and move text.

VI Navigation Commands:

j(or down arrow) To move the cursor to the next line (move down) 
k(or up arrow) To move the cursor to the previous line (move up) 
h(or left arrow)  To move left one character
l(or right arrow) To move right one character
H To move the cursor to current page beginning of the first line.
G To move the cursor to current page beginning of the last line.
b To move the cursor previous word first character
e To move the cursor next word last character
w To move the cursor to next word first character
^ Go to beginning of line 
0 Go to beginning of line
$ Go to the end of the line
CTRL+F forward 1 screen
CTRL+B backward 1 screen
CTRL+D down (forward) 1/2 screen
CTRL+U up (backward) 1/2 screen

Copy & Paste:

Key Use
y+w  To copy rest of the word from current cursor position. 
n+y+w  To copy n number of words from the current cursor position.
y+y To copy a line
n+y+y To copy n lines
p(lowerCase) To paste a copied words/lines after the current position of the cursor
P(uppercase) To paste a copied words/lines before  the current position of the cursor


x deletes a single character 
n+X  To delete n number of characters from the cursor position in a line.
d+w To delete rest of a word from current cursor position
n+d+w  To delete n  number of words from the cursor position in a line
d$ Delete rest of line from current cursor position
D Delete rest of line from current cursor position
d+d To delete an entire line
n+d+d To delete n lines from current cursor position

Few More Important Command Mode VI commands:

u Undo changes (only one time) 
U Undo all changes to the current line 
~ To change the case of the letter
ZZ Saves the changes and quits the vi editor 

Input or Insert Mode: In this mode we can insert text into the file. We can enter the insert mode by pressing following keys in command mode:

i Inserts the text before the cursor 
I Inserts the text at the beginning of the line 
o Opens a new blank line below the cursor
O Opens a new blank line above the cursor
a Appends text after the cursor
A Appends the text after the line
r replace the single character with another character 
R replace a entire line
Esc To return to command mode

 Last line mode or Collan Mode : This is used for advance editing commands. To access the last line mode enter “:” while in command mode.

: To get to collan mode(This need to be entered every time a user wants to use collan mode command)
:+set nu Shows line numbers
:+set nonu Hides line numbers
:+enter+n  Moves the cursor to the n line
:+/keyword  To move the cursor to the line starting with the specific keyword
:+n+d Deletes nth line
:+5,10d Delete line from 5th line to 10th line
:+7 co 32 Copies 7th line and paste in 32nd line
:+10,20 co 35 Copies lines from 10th line to 20th line and paste it from 35th line

:+%s/old_text/new_text/g  Searches old string and replaces with the new string
:+q+! Quits vi editor without saving
:+w Saves the file with changes by writing to the disk
:+w+q Save and exit the vi editor
:+w+q+! Save and quit the VI Editor forcefully.
1,$s/$/” -type=Text_to_be_appended Append text at the end of the line

Using VI editor Command:

vi options <file name>
The options are discussed below:
-r : To recover a file from system crash while editing.
-R : To open a file in read only mode.


Viewing Files in Read Only Mode:
view <file name>
This is also used to open the file in read only mode. To exit type ‘:q‘ command.


Automatic Customization of a VI session:
1. Create a file in the user’s home directory with the name .exrc
2. enter the set variables without preceding colon
3. Enter each command in one line.
VI reads the .exrc file each time the user opens the vi session.
#cd ~
#touch .exrc
#echo “set nu”>.exrc
#cat .exrc
set nu
In the above example we have used set line number command. So whenever the user opens the vi session, line number is displayed.
I know its nearly impossible to keep all the above commands in mind, even I don’t have, but as we keep practicing, we will be knowing most of them.

Chmod With Examples Along With Quick Reference

July 1st, 2018, posted in Solaris

What is chmod ?

chmod ( Change Mode ) is a command line utility in Unix , Linux and other Unix like systems to change the read, write, execute permissions of a file for owner , group and others.

How to use chmod?

Chmod command is used in two ways :
1. Using octal value & position : Sets the permission for owner, group and others with octal values , 4 for read , 2 for write , 1 for execute and any sum of these number to get cumulative permissions.

chmod syntax using octal mode

2. Using symbolic values to add, remove the file permission
u for user , g for group , o for others a for all ; r for read , w for write , x for execute , + , – & = for adding , removing and assigning r w x permissions.

chmod syntax for symbolic values

3. chmod options

-R – Recursively change the permissions in the file under the directory.

chmod examples using octal mode :

  • First column shows the chmod command ,
  • second column shows how the value is calculated for the permission
  • last columns of owner, group, others shows individual octal values and actual bit set on file as seen by ls -l.
  • For setting any other permission combination for owner, group & other , pick corresponding value from each column and use with chmod command , for example chmod 264 file , chmod 400 file , chmod  755 file etc.
Permissions Value octal value & bit set
Read write Execute
$chmod 777 file
4+2+1 7
Read & Write
$chmod 666 file
4+2 6
Read & Execute
$chmod 555 file
4+1 5
r_ x
r_ x
r_ x
Read only
$chmod 444 file
4 4
r_ _
r_ _
r_ _
Write only
$chmod 222 file
2 2
Execute only
$chmod 111 file
1 1
_ _ x
_ _ x
_ _ x

chmod examples using symbolic mode :

Symbol are used to assign the permissions :

  • u – user , g – group,  o – others ,  a – all
  • +  to add permission  ,    to remove permission ,  = to assign permission
  • r w x   is used for read , write,execute ,  s  is used to set the sticky bit


  • chmod  ug+x file   ;  assign execute permission to user and group in file
  • chmod a+x  <file>  ;  assign execute permission to all in file
  • chmod o-x  <file>  ;  remove execute permission to others in file
  • chmod go+r  <file>  ;  assign read permission to group & others in file
  • chmod u+rwx ,g+rw,o+r  file

Special permissions – sticky bit , setuid , setguid bit

sticky bit

when sticky bit is set the file or script is kept in swap space and loaded in to memory on next request. This makes memory loading faster.

sticky bit is represented by t in symbol mode , for example

$chmod +t

In octal mode sticky bit is represented by 1

$chmod 1755

Set user id – setuid and set group id –  setguid bits

when these bits are set for user or groups , they are given effective permission of owner of the file during run time

for example , if file.txt is owned by root and you need to give just run time root permission to some user , you can set the setuid for file.

Following examples sets the setuid , setguid on file along with normal 755 permission.

$chmod 4755 file.txt

you need to give just run time root permission to some group of users , you can set the setgid for file.

$chmod 4755 file.txt