Results 1 to 8 of 8

Thread: Touch a list of files

  1. #1
    Join Date
    Aug 2016
    Location
    El Lago, Texas
    Beans
    746
    Distro
    Ubuntu Mate

    Touch a list of files

    I often touch a file so it shows up at the top of the file manager.

    Is there a way to touch a list of files instead of touching each one individually?

    Thanks.
    Ubuntu Mate 18.04 Bionic and Ubuntu Mate 20.04
    Mate Desktop

  2. #2
    Join Date
    Dec 2014
    Beans
    2,573

    Re: Touch a list of files

    The 'touch' command line tool will accept a list of files (for example 'touch firstfile secondfile thirdfile'). How you can do this in a file manager depends on the program you're using. On XUbuntu in Thunar there is something called 'user-defined actions' which gives you the ability to define commands to run on selected files from the context menu. A short look at 'apt search caja' shows a plugin for caja named 'caja-actions' which seems to do something similar in Mate's file manager.

    Holger

  3. #3
    Join Date
    Aug 2016
    Location
    El Lago, Texas
    Beans
    746
    Distro
    Ubuntu Mate

    Re: Touch a list of files

    touch test1 test2 works, but I have to manually specify each file.

    Looking for something automated.
    Ubuntu Mate 18.04 Bionic and Ubuntu Mate 20.04
    Mate Desktop

  4. #4
    Join Date
    Jan 2008
    Beans
    164
    Distro
    Kubuntu 18.04 Bionic Beaver

    Re: Touch a list of files

    Define automated, and keep in mind that automated does not mean mind reading. You want to touch a list of files, so you have to pass this list to a program somehow, and one way of doing it by listing files on the command line. If you have a list of files in a text file you may pass it to touch by running " touch `cat filelist` " or better still " xargs touch <filelist ". If by 'automated' you mean 'integrated with my favourite file manager' it depends on the file manager e.g. in mc you can run a program for selected files by using macro substitution e.g. " touch %t " or %T, %u, %U.

  5. #5
    Join Date
    May 2010
    Beans
    3,240

    Re: Touch a list of files

    Something like

    Code:
    #!/bin/bash
    for file in filename1 filename2 filename3
    do
    touch $file
    done
    exit 0

  6. #6
    Join Date
    Oct 2005
    Location
    Lab, Slovakia
    Beans
    10,790

    Re: Touch a list of files

    Here are some ideas:

    Touch everything:
    $ touch *

    Make a list of filenames:
    $ ls | tr '\n' '\n' > filelist

    Now you can edit the list and remove filenames you don't want to touch.

    Use cat to pass the filenames to touch:
    $ cat filelist | touch

    Use redirection to pass the filenames to touch:
    $ touch < filelist

  7. #7
    Join Date
    Jan 2008
    Beans
    164
    Distro
    Kubuntu 18.04 Bionic Beaver

    Re: Touch a list of files

    Quote Originally Posted by HermanAB View Post
    Use cat to pass the filenames to touch:
    $ cat filelist | touch

    Use redirection to pass the filenames to touch:
    $ touch < filelist
    touch cannot read filenames from stdin

  8. #8
    Join Date
    Aug 2016
    Location
    El Lago, Texas
    Beans
    746
    Distro
    Ubuntu Mate

    Re: Touch a list of files

    #!/bin/bash
    #
    #----------------------------------------------------------------------------
    #
    # If I make a list of files I want to touch in files.txt, this
    # will touch all the files in that list.
    # The files must be in a text file with each on it's own line
    #----------------------------------------------------------------------------
    <files.txt xargs -d'\n' touch
    Ubuntu Mate 18.04 Bionic and Ubuntu Mate 20.04
    Mate Desktop

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •