JosiahMaybe
Gold Coder
How would that set timestamp from backup file or what is that for? I am trying to be able to set created at times in Linux. X E.
By registering with us, you'll be able to discuss, share and private message with other members of our community.
SignUp Now!Wait... let me make sure I am understanding what I just read correctly...you are wanting to edit the actual created at timestamp of a file, after you extract it from the tarball?How would that set timestamp from backup file or what is that for? I am trying to be able to set created at times in Linux. X E.
Just to make sure I am understanding you correctly...if that is your goal, the this would do itWait... let me make sure I am understanding what I just read correctly...you are wanting to edit the actual created at timestamp of a file, after you extract it from the tarball?
touch -t 202301011234.56 filename
you do need root privs for this, so you may need to sudo and run your scriptJust to make sure I am understanding you correctly...if that is your goal, the this would do it
where, "202301011234.56" would set the creation date to filename to January 1, 2023 at 12:34:56, in the format YYYYMMDDhhmm[.ss]Bash:touch -t 202301011234.56 filename
Newer versions may have that kind of precision... I would stick with hhmm[.ss] for reliabilityYes I want to set created at time. Also, I am trying for it at system precision so can it be like YYYYMMDDhhmm[.ss].nnnnnn? Like my system has that precision. I understand I need root privileges. Would that work with an already created file? X E.
Did you run your script as sudo?I tested that touch command and Java command. Both fail to set creation time. Like my recorder is not useless but like all else is. X E.
#!/bin/bash
if ! command -v touch &> /dev/null; then
echo "Need 'touch' command. X E."
exit 1
fi
#12/28/2023, 9:26PM, start, X E. 9:55PM, done for today. X E. 9:59PM, like done for today, X E.
# Specify the file path
file_path="$(pwd)/propsXE.txt"
#12/30/2023, 4:19PM, started work today.
echo "input directory inside origin to restore from"
read origin
if [ -z "$origin" ]; then
origin=""
fi
echo "input directory to move to"
read dest
if [ -z "$dest" ]; then
dest=""
fi
if [[ "$dest" != */ ]]; then
dest="$dest/"
fi
echo "input device to move to path, e.g. /dev/sda1."
read device
if [ -z "$device" ]; then
device=""
fi
#Check if device exists
if [ ! -b "$device" ]; then
echo "device does not exist. X E."
exit 1
fi
# Check if the file exists
if [ -f "$file_path" ]; then
# Open the file for reading
exec 3< "$file_path"
index=0;
result="";
change="";
access="";
inode=0;
formatted_time="";
# Read each line of the file
while IFS= read -r line <&3; do
if [ $index -eq 0 ]; then
if [[ -n $origin ]]; then
result="${line##$origin}"
else
result=$line;
fi
if [[ "$result" == /* ]]; then
result="$dest${result##/}";
else
result="$dest$result";
fi
if [ ! -f $result ]; then
if [ $line -ne "X E." ]; then
echo "Error $result does not exist."
fi
else
inode=$(stat -c "%i" "$line")
fi
elif [ $index -ne 9 ] && [ -f $result ]; then
if [ $index -eq 1 ]; then
# Format time
formatted_time=$(date -d "$line" +%s.%N)
# Run debugfs command
debugfs -w -R 'set_inode_field $inode crtime $formatted_time' $device
#echo "created"
elif [ $index -eq 2 ]; then
touch -m -t "$line" "$result"
#echo "last modified"
elif [ $index -eq 3 ]; then
#echo "last access"
touch -a -t "$line" "$result"
elif [ $index -eq 4 ]; then
#echo "change"
# Format time
formatted_time=$(date -d "$line" +%s.%N)
# Run debugfs command
debugfs -w -R 'set_inode_field $inode ctime $formatted_time' $device
elif [ $index -eq 5 ]; then
#echo "permissions"
chmod $line $result
elif [ $index -eq 6 ]; then
#echo "owner"
chown $line $result
elif [ $index -eq 7 ]; then
#echo "group"
chgrp $line $result
#else
#echo "inode $line"
fi
fi
# Process the line
index=$((index+1));
if [ $index -eq 10 ]; then
#touch -a -t "$change" "$result"
#touch -a -t "$access" "$result"
index=0;
fi
done
# Close the file
exec 3<&-
else
echo "File not found: $file_path"
fi
echo "Done. X E."
#X E.
function startXE() {
if [ -f "$1propsXE.txt" ]; then
echo "$1propsXE.txt exists";
rm -i "$1propsXE.txt";
if [ -f "$1propsXE.txt" ]; then
return;
else
echo "File deleted";
fi
else
echo "$1propsXE.txt does not exist";
fi
tester="$1propsXE.txt";
#export -f writeXE;
#find $1 -mindepth 1 -not -path '*/\.*' -exec bash -c ''writeXE' $0 '$tester'' {} \;
#find $1 -mindepth 0 -exec bash -c "writeXE {} $tester" \;
#find $1 -mindepth 0 -exec bash -c "writeXE {} $tester" \;
#find $1 -mindepth 0 -exec bash -c 'writeXE "$0" "$1"' {} "$tester" \;
echo "X E." >> "$1propsXE.txt";
echo "Done. X E.";
#X E.
}
Code Forum is a community platform where coding enthusiasts can connect with other developers, engage in discussions, ask for help, and share their knowledge with a supportive community. It's a perfect place to improve your coding skills and to find a community of like-minded individuals who share your passion for coding.
We use essential cookies to make this site work, and optional cookies to enhance your experience.