Sample Header Ad - 728x90

Unix & Linux Stack Exchange

Q&A for users of Linux, FreeBSD and other Unix-like operating systems

Latest Questions

2 votes
6 answers
63 views
Check if multiple files exist on a remote server
I am writing a script that locates a special type of file on my system and i want to check if those files are also present on a remote machine. So to test a single file I use: ssh -T user@host [[ -f /path/to/data/1/2/3/data.type ]] && echo "File exists" || echo "File does not exist"; But since I hav...
I am writing a script that locates a special type of file on my system and i want to check if those files are also present on a remote machine. So to test a single file I use: ssh -T user@host [[ -f /path/to/data/1/2/3/data.type ]] && echo "File exists" || echo "File does not exist"; But since I have to check blocks of 10 to 15 files, that i would like to check in one go, since I do not want to open a new ssh-connection for every file. My idea was to do something like: results=$(ssh "user@host" ' for file in "${@}"; do if [ -e "$file" ]; then echo "$file: exists" else echo "$file: does not exist" fi done ' "${files_list[@]}") Where the file list contains multiple file path. But this does not work, as a result, I would like to have the "echo" string for every file that was in the files_list.
Nunkuat (123 rep)
Aug 6, 2025, 12:31 PM • Last activity: Aug 6, 2025, 03:31 PM
88 votes
8 answers
91087 views
List the files accessed by a program
`time` is a brilliant command if you want to figure out how much CPU time a given command takes. I am looking for something similar that can list the files being accessed by a program and its children. Either in real time or as a report afterwards. Currently I use: #!/bin/bash strace -ff -e trace=fi...
time is a brilliant command if you want to figure out how much CPU time a given command takes. I am looking for something similar that can list the files being accessed by a program and its children. Either in real time or as a report afterwards. Currently I use: #!/bin/bash strace -ff -e trace=file "$@" 2>&1 | perl -ne 's/^[^"]+"(([^\\"]|\\[\\"nt])*)".*/$1/ && print' but its fails if the command to run involves sudo. It is not very intelligent (it would be nice if it could only list files existing or that had permission problems or group them into files that are read and files that are written). Also strace is slow, so it would be good with a faster choice.
Ole Tange (37348 rep)
Aug 16, 2011, 02:51 PM • Last activity: Aug 5, 2025, 10:58 PM
13 votes
3 answers
4773 views
Tar produces different files each time
I often have large directories that I want to transfer to a local computer from a server. Instead of using recursive `scp` or `rsync` on the directory itself, I'll often `tar` and `gzip` it first and then transfer it. Recently, I've wanted to check that this is actually working so I ran md5sum on tw...
I often have large directories that I want to transfer to a local computer from a server. Instead of using recursive scp or rsync on the directory itself, I'll often tar and gzip it first and then transfer it. Recently, I've wanted to check that this is actually working so I ran md5sum on two independently generated tar and gzip archives of the same source directory. To my suprise, the MD5 hash was different. I did this two more times and it was always a new value. Why am I seeing this result? Are two tar and gzipped directories both generated with the same version of GNU tar in the exact same way not supposed to be exactly the same? For clarity, I have a source directory and a destination directory. In the destination directory I have dir1 and dir2. I'm running: tar -zcvf /destination/dir1/source.tar.gz source && md5sum /destination/dir1/source.tar.gz >> md5.txt tar -zcvf /destination/dir2/source.tar.gz source && md5sum /destination/dir2/source.tar.gz >> md5.txt Each time I do this, I get a different result from md5sum. Tar produces no errors or warnings.
Alon Gelber (133 rep)
Apr 17, 2018, 02:55 PM • Last activity: Aug 1, 2025, 01:16 PM
1 votes
3 answers
2435 views
find and replace with the value in another file
I have two files with different formats with columns tab spaced. I have to compare the columns `column1`, `column2` of `file1` with `file2`. If they matches, I need to replace the value in `column6` of `file1` with the value in `column3` of `file2`. I have tried using `awk` but I am not able to repl...
I have two files with different formats with columns tab spaced. I have to compare the columns column1, column2 of file1 with file2. If they matches, I need to replace the value in column6 of file1 with the value in column3 of file2. I have tried using awk but I am not able to replace the value. Could you please advise on the below snippet ? awk 'FILENAME == ARGV { m[$1,$2] = $6; next; } { if (($1,$2) in m) { m[$6]= $3; print m[$6]; } }' file1 file2 top few lines of file1 1201 12011 1 0 0 0 1 1202 12021 1 0 0 0 1 1203 12031 1 0 0 0 1 1204 12041 1 0 0 0 2 1207 12071 1 0 0 0 2 1209 12091 1 0 0 0 1 1210 12101 1 0 0 0 1 1212 12121 1 0 0 0 1 1213 12131 1 0 0 0 1 1214 12141 1 0 0 0 2 top few lines of file2 1201 12011 1 1202 12021 1 1203 12031 1 1204 12041 1 1206 NA 1 1207 12071 2 1208 NA 1 1209 12091 2 1210 12101 2 I want to assign the values from file2 to file1 column as I would like to write the updated content into another file out.txt Tried the below code as per the comments: awk '{ if (FNR==NR) { a[FNR]=$1;b[FNR]=$2;c[FNR]=$3} else { if (a[FNR] == $1 && b[FNR] ==$2) { $6=c[FNR]} else {$6=$6}; print $0; } }' file2 file1 Got this output 1201 12011 1 0 0 1 1 1202 12021 1 0 0 1 1 1203 12031 1 0 0 1 1 1204 12041 1 0 0 1 2 1207 12071 1 0 0 0 2 1209 12091 1 0 0 0 1 1210 12101 1 0 0 0 1 1212 12121 1 0 0 0 1 1213 12131 1 0 0 0 1 1214 12141 1 0 0 0 2
Prradep (203 rep)
Aug 4, 2015, 01:29 PM • Last activity: Jul 15, 2025, 09:02 PM
121 votes
14 answers
85511 views
Find duplicate files
Is it possible to find duplicate files on my disk which are bit to bit identical but have different file-names?
Is it possible to find duplicate files on my disk which are bit to bit identical but have different file-names?
student (18865 rep)
Apr 4, 2013, 01:18 PM • Last activity: Jul 10, 2025, 03:09 PM
7 votes
3 answers
2667 views
Set directory timestamps to most recently modified file within (recursively)
How do I change the timestamp of a directory and all the sub-folders within that directory to reflect the modification times of the contained files? For example with this directory structure: [Jan 9] root ├── [Jan 3] file1 ├── [Jan 7] file2 ├── [Jan 6] sub1 │   ├── [Jan 2] file3 │ &#1...
How do I change the timestamp of a directory and all the sub-folders within that directory to reflect the modification times of the contained files? For example with this directory structure: [Jan 9] root ├── [Jan 3] file1 ├── [Jan 7] file2 ├── [Jan 6] sub1 │   ├── [Jan 2] file3 │   └── [Jan 1] file4 └── [Jan 4] sub2 └── [Jan 8] file5 Here is a one liner to generate that: mkdir -p root/sub1 root/sub2 && touch -d '2018-01-08' root/sub2/file5 && touch -d '2018-01-04' root/sub2/ && touch -d '2018-01-01' root/sub1/file4 && touch -d '2018-01-02' root/sub1/file3 && touch -d '2018-01-06' root/sub1/ && touch -d '2018-01-07' root/file2 && touch -d '2018-01-03' root/file1 && touch -d '2018-01-09' root/ It can be listed with tree -D I'd like to change the timestamps on the three directories to be: [Jan 8] root ├── [Jan 3] file1 ├── [Jan 7] file2 ├── [Jan 2] sub1 │   ├── [Jan 2] file3 │   └── [Jan 1] file4 └── [Jan 8] sub2 └── [Jan 8] file5 Note: - The current timestamps on the directories are completely ignored and the new time stamps are set only based on the contents. - Time stamps bubble up to multiple levels of parent directories. The reason that I'm doing this is for a directory that gets copied with rsync. The directory is checked into git and could get rsynced from any place that has the repository checked out. To ensure that rsync is consistent and idempotent from the various places, I need to ensure that the time stamps and permissions of everything are in a known state. I already have a script that sets the timestamps of files based on when they were committed to git. I also have a script that sets the permissions on all files and directories to a known state. The only portion that I'm struggling with is bubbling time stamps from the files up to parent directories. I would like one line or short script that I can run from the command line to set directory timestamps based on the timestamps of their contents.
Stephen Ostermiller (1044 rep)
Jan 10, 2018, 11:45 AM • Last activity: Jul 9, 2025, 08:04 AM
25 votes
7 answers
20564 views
Suppress filename from output of sha512sum
Maybe it is a trivial question, but in the `man` page I didn't find something useful. I am using Ubuntu and `bash`. The normal output for `sha512sum testfile` is testfile How to suppress the filename output? I would like to obtain just
Maybe it is a trivial question, but in the man page I didn't find something useful. I am using Ubuntu and bash. The normal output for sha512sum testfile is testfile How to suppress the filename output? I would like to obtain just
BowPark (5155 rep)
Feb 25, 2016, 01:41 PM • Last activity: Jul 5, 2025, 09:57 PM
1 votes
2 answers
2168 views
How do I transfer images from a Fedora 20 computer to an iPhone?
I have a laptop running Fedora20. I have an iPhone4S. I have installed the software suggested [here][1] which allows my laptop to read the iPhone. I connect my phone to the laptop using a USB cable. I can see a bunch of files, including all the images that are on the iPhone. I can transfer images fr...
I have a laptop running Fedora20. I have an iPhone4S. I have installed the software suggested here which allows my laptop to read the iPhone. I connect my phone to the laptop using a USB cable. I can see a bunch of files, including all the images that are on the iPhone. I can transfer images from the iPhone to the laptop. **What I want to do is transfer images from the laptop to the iPhone.** When I copy and paste images I don' get any error message, but the images never appear on the iPhone. **How can I sync these images to the iPhone?** I do not have any other OS available. (Asking here because "AskDifferent", the Apple StackExchange site is hopeless)
DanBeale (312 rep)
Feb 8, 2015, 07:38 PM • Last activity: Jul 4, 2025, 10:00 AM
3 votes
1 answers
2157 views
dialog menu to display files, select one of them and then able to delete it
I want to be able to display files under a given directory, then select one of the files and be able to delete it. Here's what I've found so far. Can anybody help? let i=0 # define counting variable W=() # define working array while read -r line; do # process file by file let i=$i+1 W+=($i "$line")...
I want to be able to display files under a given directory, then select one of the files and be able to delete it. Here's what I've found so far. Can anybody help? let i=0 # define counting variable W=() # define working array while read -r line; do # process file by file let i=$i+1 W+=($i "$line") done &2 2>&1 1>&3) # show dialog and store output clear if [ $? -eq 0 ]; then # Exit with OK readlink -f $(ls -1 /home | sed -n "echo "$FILE p" | sed 's/ //'") fi
NickG95 (31 rep)
Mar 14, 2016, 09:50 AM • Last activity: Jun 27, 2025, 06:04 AM
0 votes
1 answers
51 views
bbe combine 2 files using blocks
I have 2 files: nand and spare. I need to combine them like this: first 512b from nand + first 16b from spare + second 512b from nand + second 16b from spare + and so on I'm on Kali.
I have 2 files: nand and spare. I need to combine them like this: first 512b from nand + first 16b from spare + second 512b from nand + second 16b from spare + and so on I'm on Kali.
Alex Alexandru (3 rep)
Jun 26, 2025, 11:04 AM • Last activity: Jun 26, 2025, 11:29 AM
1 votes
2 answers
2173 views
How to compare two file names
I want to compare two files in a folder and delete the number in the name which is the smaller of the two. For instance, say the names were `yearMonthDay.txt`. I want to compare which is a smaller number and `sudo rm` it. I know I can get the numbers via: ```none find *txt | awk -F'[_.]' '{ print $1...
I want to compare two files in a folder and delete the number in the name which is the smaller of the two. For instance, say the names were yearMonthDay.txt. I want to compare which is a smaller number and sudo rm it. I know I can get the numbers via:
find *txt | awk -F'[_.]' '{ print $1}'
How then next should I compare it? Using system variables? I actually haven't used shell variables before.
1toneboy (465 rep)
Nov 27, 2021, 02:26 AM • Last activity: Jun 25, 2025, 01:07 PM
0 votes
0 answers
43 views
Cannot access files to delete
I currently use freefilesync on ubuntu 24.04 to back up my data. A couple of months ago I started to get errors on the external backup disk that a quick (and ineffective) look didn't resolve so I just ignored them. Today I delved deeper. If I use Files to open one of the problem directories it gives...
I currently use freefilesync on ubuntu 24.04 to back up my data. A couple of months ago I started to get errors on the external backup disk that a quick (and ineffective) look didn't resolve so I just ignored them. Today I delved deeper. If I use Files to open one of the problem directories it gives an error "This location could not be displayed" with a file name stating: input/output error. Double Commander (my preferred file manager) opens the directory fine but shows no files. However, using ls -l in a terminal lists a number of files with reasonable file names but where the attributes, owner, group, etc should be listed there are only question marks. Unsurprisingly attempting to run chmod, chown, rm, etc just results in an imput/output error. I also tried to check the partition with GParted but it crashed, Is there an easy way top resolve this issue? I suspect the best option is to bite the bullet and reformat the external disk and backup my 2TB data from scratch. My only concern is that, despite knowing better, I have just the one external disk so would be without a backup for a short while. Any suggestions gratefully received Keith
KeithW (1 rep)
Jun 20, 2025, 08:25 PM • Last activity: Jun 21, 2025, 05:01 AM
0 votes
0 answers
69 views
best way to have multiple homes?
I have a number of drives on a given machine with different disk configuration. - root drive. - 2 disk mirror. - zfs array. To accommodate a variety of failure scenarios, I want user homes to be: - zfs when it's up and working. `/mypool/mydataset/home/username` - mirror if zfs is down but mdadm is w...
I have a number of drives on a given machine with different disk configuration. - root drive. - 2 disk mirror. - zfs array. To accommodate a variety of failure scenarios, I want user homes to be: - zfs when it's up and working. /mypool/mydataset/home/username - mirror if zfs is down but mdadm is working. /mymirror/home/username - root drive if there's something wrong with both zfs and mdadm. /home/username Files will need to be synced across all 3. What's the best way to achieve this? Best in terms of reliability: 1. fault tolerant (works even when some software or hardware is broken - i.e. the more faults it will tolerate, the better. ideally will "just work" with cpu/ram/mb/boot drive working and everything else is broken, including nic, vga card, all other hdds, etc; while being transplantable to new cpu/ram/mb/boot drive to accommodate those failures) 2. tamper proof - users can't stuff it up to remove this "protection".
John (109 rep)
Jun 20, 2025, 01:40 AM • Last activity: Jun 20, 2025, 02:36 AM
6 votes
1 answers
703 views
How to find files by size that are not divisible by 4096 and round them up
In Linux in a Folder there are many files, all created with `fallocate` with random size. How to find files whose size is not divisible by 4096 and correct the filesize (rounded up) to a multiple of 4096? They can be found with : find . -type f -printf '%s\t%p\n' | awk -F'\t' '{size=$1; file=$2; if...
In Linux in a Folder there are many files, all created with fallocate with random size. How to find files whose size is not divisible by 4096 and correct the filesize (rounded up) to a multiple of 4096? They can be found with : find . -type f -printf '%s\t%p\n' | awk -F'\t' '{size=$1; file=$2; if (size % 4096 != 0) print file}' But how to size them up that the filesize is divisible by 4096 ?
Banana (189 rep)
Jun 16, 2025, 01:34 AM • Last activity: Jun 16, 2025, 11:29 PM
1 votes
2 answers
781 views
Files copied with cp are disappearing or not arriving as expected
I'm trying to copy ```~/Desktop/profiles/a.mobileprovision``` to ```~/Library/MobileDevice/Provisioning Profiles```. Whether or not that's a good idea is not the topic of this question. The files never appear, even when doing an ```ls -la```. Here's my procedure. 1. ```$ cd ~/Library/MobileDevice/Pr...
I'm trying to copy
~/Desktop/profiles/a.mobileprovision
to
~/Library/MobileDevice/Provisioning Profiles
. Whether or not that's a good idea is not the topic of this question. The files never appear, even when doing an
-la
. Here's my procedure. 1.
$ cd ~/Library/MobileDevice/Provisioning Profiles
// cd is working as expected. 2.
$ cp ~/Desktop/profiles/a.mobileprovision .
3.
$ find . -name "a.mobileprovision"
nothing. Permissions for the directory:
-xr-x
, so I should be allowed. I'm on a Mac (Monterey 12.5), so I've also tried: 1. Opening up
~/Library/MobileDevice/Provisioning Profiles
in Finder and dragging and dropping
.mobileprovision
, but it disappears upon releasing the mouse. I've got hidden files showing. No luck. 2. Copying
.mobileprovision
to
~/Library/MobileDevice
. This works fine, but when I try to copy it to
~/Library/MobileDevice/Provisioning Profiles
, it does not. **Responses to comments:** 3. Doing
$ pwd
after the cd yields
~/Library/MobileDevice/Provisioning Profiles
4. Doing
$ cp ~/Desktop/profiles/a.mobileprovision ~/Library/MobileDevice/Provisioning Profiles
has the same effect: no copy performed. 5. Mac version: Monterey 12.5 (switched to bash from zsh). 6.
$ cp -v ~/Desktop/profiles/a.mobileprovision .
yields
~/Desktop/profiles/a.mobileprovision -> ./a.mobileprovision
7.
. -name ""
while in
~/Library/MobileDevice/Provisioning Profiles
is working. 8. Tried
~/Desktop/profiles/a.mobileprovision ~/Library/MobileDevice/'Provisioning Profiles'
. Same problem. Thanks for the help!
h.and.h (123 rep)
Feb 25, 2023, 07:51 PM • Last activity: Jun 12, 2025, 12:31 PM
139 votes
15 answers
243079 views
Linux ls to show only file name, date, and size
How can I use `ls` on Linux to get a listing of files with only their name, date, and size? I don't need to see the other info such as owner or permissions Is this possible?
How can I use ls on Linux to get a listing of files with only their name, date, and size? I don't need to see the other info such as owner or permissions Is this possible?
Pinkie (1493 rep)
Oct 7, 2011, 03:33 AM • Last activity: Jun 11, 2025, 04:12 PM
2 votes
2 answers
2064 views
Search one file to see if it contains information from another file
I have two files. The first is `unip.txt` and the second is `ipex.txt` and each file contains IP addresses. `unip.txt`: ```none 49.235.113.205 50.115.166.136 51.15.70.104 51.15.87.74 51.15.134.103 146.148.13.9 148.70.23.131 148.72.212.161 148.216.29.46 149.56.141.193 ``` `ipex.txt`: ```none 51.15.13...
I have two files. The first is unip.txt and the second is ipex.txt and each file contains IP addresses. unip.txt:
49.235.113.205
50.115.166.136
51.15.70.104
51.15.87.74
51.15.134.103
146.148.13.9
148.70.23.131
148.72.212.161
148.216.29.46
149.56.141.193
ipex.txt:
51.15.134.103
148.70.23.131
151.141.0.0
97.89.32.238
I'm trying to figure out how to basically search the unip.txt file to see if it contains any IP from the ipex.txt file. I imagine that it would be a loop to search through every line, but I'm not sure how to do it.
newguy202020 (23 rep)
Apr 28, 2021, 01:01 AM • Last activity: Jun 9, 2025, 04:36 PM
0 votes
0 answers
24 views
How does the search algorithm in Gnome Files traverse the directory tree?
If I place myself in some directory C and press the search lens and type some keywords, are files matching the keywords in directory C displayed first? This is not obvious, for instance if the search algorithm operated by alphabetical order (hence if there's some subfolder starting by "a" then resul...
If I place myself in some directory C and press the search lens and type some keywords, are files matching the keywords in directory C displayed first? This is not obvious, for instance if the search algorithm operated by alphabetical order (hence if there's some subfolder starting by "a" then results from that subfolder could be displayed before files from C which start by "b")
user324831 (113 rep)
Jun 2, 2025, 06:28 PM • Last activity: Jun 2, 2025, 07:12 PM
0 votes
2 answers
44 views
when opening a FIFO for reading+writing, and blocking - how to tell if other side opened for reading or writing?
If I open a fifo for reading+writing in blocking mode: fd = open("foo", "O_RDWR"); Then it blocks until someone on the other end opens it for either reading or writing. But how do I know which? if(???) { read(fd, .......); } else { write(fd, ......); } close(fd); (I need that close, because if I am...
If I open a fifo for reading+writing in blocking mode: fd = open("foo", "O_RDWR"); Then it blocks until someone on the other end opens it for either reading or writing. But how do I know which? if(???) { read(fd, .......); } else { write(fd, ......); } close(fd); (I need that close, because if I am writing I need to send an EOF to the other end. And any writer will send a single line through and close, so I also need to close if I read.) What do I put instead of the ??? to figure out what the other end did? Is non-blocking and select() my only option? Is there a way to inspect fd and see if it's ready for reading or writing?
Ariel (117 rep)
May 30, 2025, 06:30 PM • Last activity: May 31, 2025, 06:15 AM
3 votes
4 answers
287 views
Lines 1,2,3,4,...,n-1, n to lines n,n-1, ...,4,3,2,1
I just realized that I could solve [this problem][1] by reversing line numbers from 1, 2, 3,...,n to n, n-1, ..., 3,2,1 and then use the same logic as earlier. So I want to know how can I reverse the order of lines? [1]: https://unix.stackexchange.com/questions/20577/how-can-i-prepend-a-tag-to-the-b...
I just realized that I could solve this problem by reversing line numbers from 1, 2, 3,...,n to n, n-1, ..., 3,2,1 and then use the same logic as earlier. So I want to know how can I reverse the order of lines?
user2362
Sep 18, 2011, 03:59 PM • Last activity: May 21, 2025, 08:12 AM
Showing page 1 of 20 total questions