MoonPoint Support Logo

 


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



Advanced Search
January
Sun Mon Tue Wed Thu Fri Sat
 
16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
2018
Months
JanFeb Mar
Apr May Jun
Jul Aug Sep
Oct Nov Dec


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/gloves.zip
$

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.

References:

  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:

apple
banana
clementine
date
eggplant
fig
grape

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
banana
clementine
date
eggplant
fig
grape
$

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
eggplant
fig
grape
$

[ 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:

game/Update
tar: game/Update: Cannot open: File exists
game/FAQ
tar: game/FAQ: Cannot open: File exists
game/CONVERT.22
tar: game/CONVERT.22: Cannot open: File exists
game/BETA
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
orange
blue purple blue
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 8.247.90.236.

15:12:46.491073 IP (tos 0x0, ttl 64, id 21907, offset 0, flags [DF], proto TCP (
6), length 52)
    moonpoint.com.33309 > 8.247.90.236.http: 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)
    8.247.90.236.http > moonpoint.com.33309: 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)
    moonpoint.com.33309 > 8.247.90.236.http: 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:

DESCRIPTION
     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

Wed, Sep 14, 2016 10:31 pm

fold

The fold command, which is found on Mac OS X and Linux systems, allows you to "fold" the contents of specified files, or the standard input if no files are specified, breaking the lines to have a maximum of eighty characters/columns by default, though you can also specify that the line breaks be made at some other character width with the -w width option.

[ More Info ]

[/os/unix/commands] permanent link

Sat, Sep 10, 2016 10:41 pm

zgrep

If you wish to search for information within a .gz file produced by the gzip utility, which is a tool used for data compression, you don't have to uncompress the file first. Instead, you can use the zgrep utility. E.g., if I wished to search for the string "Splunk" in a gzip compressed text file, if I used grep, I wouldn't be able to find the text for which I was searching since the contents of the file were compressed, but I could find it with zgrep.

$ grep Splunk tools.txt.gz
$ zgrep Splunk tools.txt.gz
Splunk

You can use the same options with the zgrep command that you can use with grep - see zgrep man page. E.g., I could determine how many times the pattern for which I'm searching occurs in the file using the -c option.

$ zgrep -c "Splunk" tools.txt.gz
1
$

The zgrep utility is present by default on Mac OS X systems. You can run it from a command line interface by opening a Terminal window (Terminal is found in the /Applications/Utilities directory). It is also found on Linux systems. E.g., for CentOS Linux systems, it will be present if the gzip package has been installed.

$ rpm -q --whatprovides /usr/bin/zgrep
gzip-1.5-7.el7.x86_64
$

[/os/unix/commands] permanent link

Thu, Sep 08, 2016 10:18 pm

Comparing files with comm

I needed to compare two files on a CentOS Linux system to find the lines in one file that didn't appear in the other. I.e., I had a file bounced.txt with a list of email addresses that had experienced bounced messages. Some, but not all of those email address were part of a mailing list stored at /etc/mail/mailinglist.txt. I wanted to see only those lines in bounced.txt that did not appear in mailinglist.txt. The comm utility, which is also present on Mac OS X systems, allows you to compare two files and determine which lines occur in one but not another file.

I was able to find the lines that appeared in bounced.txt, but not mailinglist.txt with the following comm command:

# comm <(sort /etc/mail/mailinglist.txt) <(sort bounced.txt) -13
bounce-600404@bounce.getaresponse.com
jasmith@example.com

You need to provide comm with sorted files for it to do its matching, which is why I used the sort command to sort the files before providing the contents of the two files to the comm command. I included the -13 because normally comm produces three columns of output as explained below in information from the comm man page:

NAME
       comm - compare two sorted files line by line

SYNOPSIS
       comm [OPTION]... FILE1 FILE2

DESCRIPTION
       Compare sorted files FILE1 and FILE2 line by line.

       With  no  options,  produce  three-column  output.  Column one contains
       lines unique to FILE1, column two contains lines unique to  FILE2,  and
       column three contains lines common to both files.

       -1     suppress column 1 (lines unique to FILE1)

       -2     suppress column 2 (lines unique to FILE2)

       -3     suppress column 3 (lines that appear in both files)

[/os/unix/commands] permanent link

Once You Know, You Newegg AliExpress by Alibaba.com

Shop Amazon Local - Subscribe to Deals in Your Neighborhood

Valid HTML 4.01 Transitional

Privacy Policy   Contact

Blosxom logo