Use this tag for questions about file management and operations on files.

learn more… | top users | synonyms (1)

3
votes
2answers
58 views

Script for changing modification time of files and directories recursively

I have many big folders with thousands of files in them and I want to use touchto set their modification times to be "original time"+3 hours. I got this script from a similar thread in superuser: ...
-3
votes
0answers
32 views

Detecting the newest file in a directory [on hold]

I need a Unix script to do the following (in bash) : Accept 1 parameter; (the parameter can only be bo or bot.) Change directory (at this time, this can be determined yourself for now); Detect the ...
0
votes
1answer
35 views

Creating an symbolic link in /bin automatically creates a second link in /usr/bin and the which command chooses /usr/bin

I just created an executable: ln -s /path/to/script.sh /bin/script then I check if everything succeeds and it does(/bin/script is created) but this has also created: /usr/bin/script and if I ...
1
vote
1answer
38 views

Move files from multiple directories to another system

Let's suppose I have a folders in the source system: AB1, AB2, AB3. And I have the same folder names AB1, AB2, AB3 in the destination system. I want to move AB1 files to AB1 and AB2 files AB2 and ...
3
votes
3answers
2k views

How to remove an empty directory (btrfs filesystem)?

I'm using the experimental btrfs filesystem. My directory looks like this: ls -la empytfolder total 4 drwxr-xr-x 1 root root 0 19. Mär 14:00 . drwxr-xr-x 1 root root 298 19. Mär 13:59 .. I ...
2
votes
3answers
70 views

Single record of a file getting splitted over multiple lines

We are using flat text files to store in teradata table after transformations from Informatica. The file contains 14 fields (~ separated). But as the records are getting scattered over multiple lines ...
1
vote
0answers
19 views

How should I distribute files/packages/software across multiple drives?

I am primarily a Windows user, but I am starting to use Linux more as I realize all the features it has. In Windows, I install my software that I use regularly on my 120GB SSD, along with the OS, ...
0
votes
1answer
27 views

How to clear log files periodically

Hi I am new to Shell script. i want to clear log files in a directory basing on the dates. I have managed to gather this code: DIR1='/home/u01/app/oracle/servers/DIR1/logs' ...
2
votes
2answers
40 views

Log new files in a directory

Is there a tool, which lets me know about the last newly created files? The still common way of using a hierarchically file system makes it hard to save files in different places, so sometimes I sort ...
-3
votes
0answers
35 views

How to save output of a python command to a file [closed]

I am writing a script and part of it is print "\nSOURCE CODE COMMAND: "+source_code_command print "\n" exec source_code_command outfile > output.txt Third line is throwing error. While ...
0
votes
2answers
29 views

Where should startup scripts for a specific user be installed?

I have one script that will run when a specific user logs in. Where should this script and its assets be placed? I was planning to put it in /usr or /bin or /var, but I was wondering if there's a ...
0
votes
1answer
31 views

Directory Permission Order [duplicate]

In Linux, let us assume we have a directory with the following properties: drwx---r-x 29 user1 group1 4096 Jun 22 14:11 dir1 can I, as user2 having group group1, navigate into dir1? Since ...
2
votes
3answers
93 views

Delete several sequential file names, but ignore part of the first

Sometimes, my scripts get trapped in infinite loops. When the loop creates new files, things get messy. I currently have this file name format: Task.4883.store.log where 4883 is a counter. I ...
7
votes
2answers
199 views

How to sync two folders with command line tools?

Having migrated to Linux from Windows, I would like to find an alternative software to Winmerge or rather learn command line tools to compare and sync two folders on Linux. I would be grateful if you ...
3
votes
2answers
157 views

Why can't I delete this file as root?

I have directory exam with 2 files in it. I need to delete files but permission is denied. Even ![rm -rf][1] command can't delete these files. I logged in as a root user.
3
votes
3answers
127 views

remove all instances of _000 from multiple files

Had to recover my music library from a HDD which died.... got everything I wanted but all music track names have _000 added at the end. I really don't fancy going through 8000 individual music tracks ...
4
votes
2answers
757 views

What does this zsh solution to “the argument list is too long” do?

I read in this answer from @Gilles the following: In zsh, you can load the mv builtin: setopt extended_glob zmodload -Fm zsh/files b:zf_\* mv -- ^*.(jpg|png|bmp) targetdir/ as a solution to ...
1
vote
2answers
62 views

How do I test if my variable is not in a set?

I am trying to modify the bash shell script and need some assistance. I have a directory with a bunch of files. What I need is to go through the files in a loop and if the file name not in a specific ...
1
vote
4answers
46 views

Find text in a file and copy it to another file

Is there any command in Linux to find text in a file and if found then copy it in another file? Using sed -i we can find text but how to copy whole line in another file?
1
vote
2answers
50 views

ldd says not found but .so file is in /usr/lib

When I type ldd with my executable file there is one not found warning. libCmp.so => not found libstdc++.so.6 => /usr/lib/arm-linux-gnueabihf/libstdc++.so.6 (0xb6ed7000) libm.so.6 => ...
1
vote
0answers
20 views

Process exceeding max open files limit

I am counting current open files by a process pid by :- cmd1:- ls /proc/$pid/fd/* | wc -l and then I am calculating percentage by fetching Max open Files limits. cmd2:- $ cat /proc/$pid/limits ...
80
votes
2answers
165k views

How can I replace a string in a file(s)?

Replacing strings in files based on certain search criteria is a very common task. How can I replace string foo with bar in all files in the current directory? do the same recursively for sub ...
1
vote
2answers
30 views

How to add some characters to filename via 'rename'?

For example I have a file named 5.jpg. How can I rename it to aaaaa.jpg with char a 5 times. I tried rename -v 's/(\d{1,})/a{$1}/g' * but this renames 5.jpg to a{5}.jpg, which is not what I want. I ...
5
votes
2answers
161 views

How to gather byte occurance statistics in binary file?

I'd like to know the equivalent of cat inputfile | sed 's/\(.\)/\1\n/g' | sort | uniq -c presented in ...
-1
votes
1answer
20 views

How can I limit a log file to a certain number of most recent logs?

I know that you can limit the size of a file in respect to bytes, but I was wondering if there was a way to limit the number of logs within the file to, for example, the most recent 200 logs.
0
votes
1answer
35 views

How do I make 'sudo ll' work? [duplicate]

Every once in awhile, I find myself needing to list files in a directory that I don't have execution permission on. So I do a sudo: >sudo ll /opt/mydir [sudo] password for civfan: sudo: ll: ...
1
vote
1answer
17 views

How do you use 'find' to update ownership of all directories, files, and symbolic links in a folder?

I'm trying to update the ownership of everything in a directory tree from me to root. I'm using find to do it a little more carefully than a recursive chown. Here are the commands I use to change ...
2
votes
2answers
39 views

How can I shuffle pages from a pdf file in a random order?

I would like to shuffle the pages of a pdf document in a random order. How can this be done?
2
votes
1answer
22 views

How to guard a set of folders from being written into by a specific process?

I would like to have a way in which a set of folders do not allow write access for a particular process. For example, I would love to have a way in which YUM/RPM is not allowed to write into /usr/bin ...
54
votes
4answers
14k views

What's the point in adding a new line to the end of a file?

Some compilers (especially C or C++ ones) give you warnings about: No new line at end of file I thought this would be a C-programmers-only problem, but github displays a message in the commit view: ...
1
vote
2answers
39 views

shell or perl script to check group have read privileges

ls -l drwx------ 8 ws web 1024 Apr 29 2013 abc drwxr-xr-x 8 ws web 1024 Oct 19 2011 def I need some script to find directories like abc which doesn't have read/execute permissions ...
1
vote
0answers
15 views

Allow move but not put in internal-sftp

is it possible with the internal-sftp to allow mv command from dir A to B but not allow put to A?
4
votes
2answers
306 views

Where is the trash can for root partition?

I use trash-put to trash files from command line. Recently, I had aliased my rm command to trash-put so that I don't accidentally delete something important. However, what happened now was that I ...
2
votes
2answers
54 views

is it possible to search for files that have a special Linux file attribute?

is it possible to search file in the linux OS that have particular file attribute as this: ---S--l--- ---S--l--- 1 root root 0 Mar 1004:25/opt/csTuner/iba/wys/tuer_lolk What is S in ...
4
votes
1answer
31 views

Why can't another user access my file when it's a full path?

I have a program that runs a command that is something like this: /home/myuser/bin>> /usr/bin/sudo -u otheruser script.py /home/otheruser/file.txt This works, but now I need this to work when ...
2
votes
2answers
34 views

One-liner to sort and uniq two outputs

I'm currently doing this to sort and uniq the output of two different commands: tshark -r sample.pcap -T fields -e eth.src -e ip.src > hello tshark -r sample.pcap -T fields -e eth.dst -e ip.dst ...
45
votes
7answers
4k views

How are file types known if not from file suffix?

I would like to know how file types are known if filenames don't have suffixes. For example, a file named myfile could be binary or text to start with, how does the system know if the file is binary ...
0
votes
0answers
19 views

Function dup2(int oldfd, int newfd) fails in for() loop [migrated]

I tried this for fun to see if it works but eventually it does not. i = open("something", O_RDWR); for(i ; i<10 ; i++); { if(dup2(i, i+1 ) == -1 ) { ...
3
votes
1answer
94 views

How do you deliberately trigger a “text file busy” error?

Very occasionally I encounter "text file busy" error while using my Linux 4.0.4 computer. I read that when the error happens, kernel is preventing modification to a file that is being "used". So I ...
1
vote
1answer
49 views

get original creation date of html file

Can I find the creation/last modified date of an html file? For example, I would like to know when some index.html file from some website was created, not when I downloaded it.
0
votes
1answer
40 views

How to create a bash script that sees all files in a directory and tells me their size and date of creation?

I'm a beginner in the field of programing/coding. I'm trying to write a simple bash script that will see all files in a directory, and then tell me each file's size and each of their dates of ...
3
votes
0answers
8 views

Is posix_fadvice / POSIX_FADV_DONTNEED functional in Linux?

If I am doing once only scanning across big files then do I need to worry about impact on the page cache or does the OS take care to avoid my scan causing pointless churn in the page cache. I want to ...
0
votes
0answers
15 views

Archlinux: Gnome 3.16 - ls & nautilus incorrect sorting

Recently switched from Xfce 4.12 DE to Gnome 3.16 and I have a problem with dirs & files sorting in terminal and nautilus. Test directories (how it should be): [ Pqr ] Abc Klm My current order ...
1
vote
1answer
57 views

Permission denied writing to mysql log

I am just testing out a new Ubuntu (Vivid 15.04) install on Vagrant, and getting problems with mysql and logging to a custom location. In /var/log/syslog I get /usr/bin/mysqld_safe: cannot create ...
3
votes
3answers
35 views

Create 2 similar-name files with content from 2-line output of a command

I perform cmd and it outputs 2 lines of text: $ cmd foo bar I need to write these to: `/long/path/x.{load,conf} Writing to this destination requires superuser privilege, which rules out manually ...
1
vote
1answer
26 views

How to see if a file has CAP_NET_ADMIN?

I ran the following command: sudo setcap cap_net_raw,cap_net_admin,cap_net_bind_service+eip `which nmap` Now I'd like to add to my ~/.zshrc a line that detects such settings and exports ...
1
vote
1answer
22 views

What do you call the supervisord and php-fpm et. al. config format?

Both php-fpm and supervisord use a config format that looks like this: [category] settings = value some_other_setting = value Is there a name for this format?
2
votes
3answers
42 views

Move file and preserve owner and mode in one atomic operation

Is there a way to move a file and preserve original owner(group) and file mode in one atomic operation? So there will not be change for others to access moved file in time when is not already set ...
0
votes
1answer
2k views

Setfattr always returns operation not supported

I'm trying to get a script working however I'm having issues with a particular line trying to set file attributes with setfattr. The line in question is ret=os.system('setfattr -n "user.dummy" -v ...
62
votes
3answers
53k views

How to tell gzip to keep original file?

I would like to compress a text file using gzip command line tool while keeping the original file. By default running the following command gzip file.txt results in modifying this file and renaming ...