MoonPoint Support Logo


Shop Amazon Warehouse Deals - Deep Discounts on Open-box and Used ProductsAmazon Warehouse Deals

Advanced Search
Sun Mon Tue Wed Thu Fri Sat
23 24 25 26 27 28 29
Jul Aug Sep
Oct Nov Dec

Fri, Jun 22, 2018 10:51 pm

Regular expression to find words/strings not ending with a character

If you wish to find strings at the end of a line that don't end with a particular character, you can use a bracket expresion with a caret character after the left square bracket in a regular expression.

Metacharacter Description
[^ ] Matches a single character that is not contained within the brackets. For example, [^abc] matches any character other than "a", "b", or "c". [^a-z] matches any single character that is not a lowercase letter from "a" to "z". Likewise, literal characters and ranges can be mixed.

[ More Info ]

[/os/unix/commands] permanent link

Sun, Feb 04, 2018 11:03 pm

Run a cronjob at the end of every year

At the end of every year, I need to create some new directories to hold log files with the directory name reflecting the new year on a CentOS Linux system. To create those directories on the last day of the year, December 31, I can use the cron utility found on Linux/Unix and OS X/MacOS systems to schedule a cronjob to run on the last day of the year. I can edit the crontab file that holds jobs to be run at a scheduled time or times by issuing the crontab command crontab -e, which will allow me to edit the file with the vi editor. If the vi editor is the default editor, which it likely is, but you are unfamiliar with that editor, you can change the editor for the current login session to the GNU nano text editor, which may be easier to use for someone unfamiliar with the vi text editor, by issuing the following command at the command line.

export EDITOR="/usr/bin/nano"

The value will be reset when you log off or you can reset it manually with the command below:

export EDITOR="/usr/bin/vi"

I can put the following line in the crontab file to run my script named end-of-year-dirs at 7:00 AM on December 31 of every year. When you add a new entry, be sure to hit the Enter key at the end of the line.

0 7 31 DEC * /home/jdoe/scripts/end-of-year-dirs

[ More Info ]

[/os/unix/commands] permanent link

Thu, Jan 18, 2018 11:55 pm

Viewing the login history for a user on a Linux or OS X system

If you want to see the IP addresses from which logins have occurred on a Linux or OS X system, you can use the last command. E.g.:

$ last ann
ann      tty2                          Thu Jan  5 20:23 - 20:27  (00:03)
ann      tty2                          Thu Jan  5 20:05 - 20:06  (00:00)
ann      tty2                          Thu Jan  5 20:01 - 20:02  (00:00)
ann      pts/0       Sun Oct 30 10:43 - 16:59  (06:16)
ann      pts/0      Tue Oct 11 12:02 - 12:03  (00:00)
ann      pts/0      Tue Oct 11 12:01 - 12:01  (00:00)
ann      pts/32      Sat Jun 11 20:03 - 20:38  (00:35)
ann      pts/32      Sat Jun 11 13:23 - 14:22  (00:58)
ann      pts/14      Sun Feb 14 17:05 - 18:28 (6+01:22)
ann      pts/6        Sun Nov  8 09:23 - 10:16  (00:52)
ann      pts/6        Sat Nov  7 08:54 - 16:42  (07:48)
ann      pts/7        Fri Nov  6 16:47 - 16:49  (00:02)
ann      pts/6        Fri Nov  6 15:48 - 23:33  (07:44)
ann      pts/0        :0               Thu Sep 10 15:25 - 12:38 (129+22:13)
ann      :0           :0               Thu Sep 10 15:24 - 12:38 (129+22:14)
ann      pts/5        :0               Sun Aug 23 11:08 - crash (18+04:03)
ann      pts/4        :0               Sat Aug 22 21:16 - crash (18+17:56)
ann      pts/3        :0               Sat Aug 22 09:14 - crash (19+05:58)
ann      :0           :0               Sat Aug 22 09:07 - crash (19+06:05)
ann      pts/2      Sun Jul 19 15:41 - 20:59 (1+05:18)
ann      pts/2      Mon Jun 22 21:28 - 20:17 (18+22:49)
ann      pts/2      Fri Feb  6 21:26 - 21:26  (00:00)
ann      pts/5      Wed Nov  5 21:07 - 22:15  (01:08)

wtmp begins Sun Oct  5 20:09:11 2014

[ More Info ]

[/os/unix/commands] permanent link

Fri, Jan 12, 2018 10:55 pm

Viewing only the files created today on a Linux system

I sometimes need to see only the files created or modified today in a directory. On a Linux system, you can pipe the output of the ls command into the grep command looking for just today's date in the input to the grep command as shown below:

$ ls -al --time-style=+%D ~/Documents/*.zip | grep $(date +%D)
-rw-r--r--. 1 joe joe   269338 01/12/18 /home/joe/Documents/

You can specify how the date is displayed with +format where format is a particular format in which you want the date displayed - see Formatting the output from the date command on a Linux system. If you use +%D, the date will be displayed as m/d/y, i.e., month/day/year, e.g. 01/12/18 for January 12, 2018. By then using the grep command to search for that value, you can limit the displayed files to only those created or modified today.

[ More Info ]

[/os/unix/commands] permanent link

Sat, Jul 08, 2017 10:57 pm

Finding files modified today

On Unix-like operating systems, such as Linux or OS X/macOS system, you can use the find command to locate files based on specified criteria. If you want to see just those files modified within the last day, you can use a command such as the one below:
$ find /home/jdoe/Documents -mtime -1 -type f -print

The command above would list those files created within the /home/jdoe/Documents directory and its subdirectories that were created in the last day, which is specified with -mtime -1. The mtime references a file's modification time and the minus one indicates you only want to see those files created today; -type f indicates you are only interested in files, not directories or other objects while -print indicates you want find to display the names of the files it finds that match the specified criteria. Note: this method will show files created within the last 24 hours, not just those created since the start of the current day at midnight the previous night. An alternative method, to see just those files created or modified since the beginning of the current day, is to specify today's date with -newermt. E.g., if today is July 8, 2017, I could use the command below to find files with a modification time newer than the specified date:

$ find /home/jdoe/Documents -newermt 2017-07-08 -type f

That command will also show me the files in the specified directory that were created or modified today.


  1. Find man page for Linux (Centos 7)
  2. Find man page for OS X (Yosemite)

Related posts:

  1. Finding files modified on or after a date on a Linux system
    Date: January 11, 2015

[/os/unix/commands] permanent link

Sat, Mar 25, 2017 10:56 pm

Using the more command to discard lines at the beginning of a file

If you wish to ignore lines at the start of output or in the beginning of a file, you can use the more command to do so. E.g., suppose I have a text file named fruit.txt that contains the following lines:


On a Linux, Unix, or OS X/macOS system, if I want to see all lines of the file but the first one, I can use the +n, where n is a number, argument to the more command. In this case, I can use more +2 fruit.txt to start the output at the second line in the file.

$ more +2 fruit.txt

If I wanted to ignore the first four lines and start output at the fifth line, I could use more +5.

$ more +5 fruit.txt

[ More Info ]

[/os/unix/commands] permanent link

Wed, Jan 11, 2017 10:36 pm

tar extraction errors - Cannot utime: Operation not permitted

I needed to copy the contents of one directory belonging to a user from one Linux system to another. While logged into her account on the source system, I created a tar file, aka a "tarball", of the directory with the command tar -cvf game.tar game to copy the contents of her "game" directory and all of its subdirectories to the tar file. The tar file was about 20 MB in size, so I compressed it with the gzip command gzip game.tar resulting in a game.tar.gz file about 5 MB in size, which I transferred to the destination system. While logged into her account on the destination system, I uncompressed the .gz file with gunzip game.tar.gz and then attempted to extract the contents of the tar file into the same directory on the destination system as on the source system. The directory already existed on the destination server because I had many months ago copied everything in her home directory from the source to the destination system. When I ran the command tar -xvf game.tar to extract the contents of the tar file, I saw files extracted, but I also saw several "Cannot open: File exists" lines in the output from the command, which terminated prematurely with the following lines:

tar: game/Update: Cannot open: File exists
tar: game/FAQ: Cannot open: File exists
tar: game/CONVERT.22: Cannot open: File exists
tar: game/BETA: Cannot open: File exists
tar: game: Cannot utime: Operation not permitted
tar: Exiting with failure status due to previous errors

[ More Info ]

[/os/unix/commands] permanent link

Sun, Jan 08, 2017 10:50 pm

Altering the contents of a file using sed

On Unix, Linux, and OS X systems, the sed (stream editor) utility can be used to modify the contents of a file replacing one string, i.e., sequence of characters, with another. E.g., suppose the file named myfile contains the following lines:

pink blue
red Blue
blue purple blue

If I want to replace all occurrences of the word "blue" with "green", I could issue the following sed command at a Bash shell prompt.

$ sed -i -e 's/blue/green/g' myfile

[ More Info ]

[/os/unix/commands] permanent link

Sat, Dec 31, 2016 6:21 pm

Using netstat to determine the process that is using a network port under Linux

While troubleshooting an isuue on a CentOS server, which functions as a web server, I used the tcpdump utility to monitor network traffic to and from the web server. I used the tcpdump command tcpdump -i enp1s4 -vvv port 80 to observe traffic on network interface enp1s4, which was the Local Area Network (LAN) interface, and only on port 80, the well-known port for HTTP traffic. Amidst the expected traffic I also saw HTTP connectivity from the server on which I was performing the troublehshooting to another web server, which seemed odd, since it wasn't immediately apparent to me why the server I was troubleshooting was connecting to that other web server at IP address

15:12:46.491073 IP (tos 0x0, ttl 64, id 21907, offset 0, flags [DF], proto TCP (
6), length 52) > Flags [F.], cksum 0x26b7 (incorrect
 -> 0x2738), seq 3599572683, ack 3802137359, win 115, options [nop,nop,TS val 28
33407685 ecr 423340583], length 0
15:12:46.515987 IP (tos 0x0, ttl 54, id 31318, offset 0, flags [none], proto TCP
 (6), length 52) > Flags [F.], cksum 0x13c6 (correct),
 seq 1, ack 1, win 114, options [nop,nop,TS val 423345561 ecr 2833407685], lengt
h 0
15:12:46.516052 IP (tos 0x0, ttl 64, id 21908, offset 0, flags [DF], proto TCP (
6), length 52) > Flags [.], cksum 0x26b7 (incorre
ct -> 0x13ac), seq 1, ack 2, win 115, options [nop,nop,TS val 2833407710 ecr 423
345561], length 0

[ More Info ]

[/os/unix/commands] permanent link

Thu, Sep 22, 2016 10:32 pm

ASCII table man page

If you need to lookup the American Standard Code for Information Interchange (ASCII) code for a particular character, you can do so on an OS X or Linux system via the ASCII man page. Simply type man ascii to see an ASCII table. E.g., from the man page on an OS X system:

     The octal set:

     000 nul  001 soh  002 stx  003 etx  004 eot  005 enq  006 ack  007 bel
     010 bs   011 ht   012 nl   013 vt   014 np   015 cr   016 so   017 si
     020 dle  021 dc1  022 dc2  023 dc3  024 dc4  025 nak  026 syn  027 etb
     030 can  031 em   032 sub  033 esc  034 fs   035 gs   036 rs   037 us
     040 sp   041  !   042  "   043  #   044  $   045  %   046  &   047  '
     050  (   051  )   052  *   053  +   054  ,   055  -   056  .   057  /
     060  0   061  1   062  2   063  3   064  4   065  5   066  6   067  7
     070  8   071  9   072  :   073  ;   074  <   075  =   076  >   077  ?
     100  @   101  A   102  B   103  C   104  D   105  E   106  F   107  G
     110  H   111  I   112  J   113  K   114  L   115  M   116  N   117  O
     120  P   121  Q   122  R   123  S   124  T   125  U   126  V   127  W
     130  X   131  Y   132  Z   133  [   134  \   135  ]   136  ^   137  _
     140  `   141  a   142  b   143  c   144  d   145  e   146  f   147  g
     150  h   151  i   152  j   153  k   154  l   155  m   156  n   157  o
     160  p   161  q   162  r   163  s   164  t   165  u   166  v   167  w
     170  x   171  y   172  z   173  {   174  |   175  }   176  ~   177 del

[ More Info ]

[/os/unix/commands] permanent link

Valid HTML 4.01 Transitional

Privacy Policy   Contact

Blosxom logo