Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- To generate a random password
- openssl rand -base64 32
- To Encrypt File
- openssl enc -pbkdf2 -in "${file_name}" -out "${file_name}.enc" -md sha512 -salt -pass "pass:${my_password}"
- The decrypting command is almost similar to the encrypting command, with an additional -d flag, and output/input file names switched
- openssl enc -d -pbkdf2 -in "${file_name}.enc" -out "${file_name}" -md sha512 -salt -pass "pass:${my_password}"
- From version 1.1.1, -pbkdf2 or -iter cypher are recommended over -aes-256-cbc. If you are using openssl version older than 1.1.1,
- replace -pbkdf2 with -aes-256-cbc. Using -aes-256-cbc with openssl version newer or equal to 1.1.1 will emit the error:
- To check openssl version: openssl version
- OpenSSL 3.0.8 7 Feb 2023 (Library: OpenSSL 3.0.8 7 Feb 2023)
- If you have multiple files or a directory. There is one more step to combine these files into
- tar -Jcf "${file_name}.tar.xz" -C . "${dir_name}"
- Encrypt Files in Linux
- # tar -czf - * | openssl enc -e -aes256 -out secured.tar.gz
- Decrypt Files in Linux
- To decrypt a tar archive contents, use the following command.
- # openssl enc -d -aes256 -in secured.tar.gz | tar xz -C test
- Encrypt & Decrypt a single file
- openssl aes-256-cbc -a -salt -in img1.jpg -out img1.jpg.enc
- openssl aes-256-cbc -d -a -in img1.jpg.enc -out img1.jpg
- Encrypt & Decrypt multiple files within one directory
- =====================================================
- To encrypt all files in one folder with a password that you set form the command line
- for f in * ; do [ -f $f ] && openssl aes-256-cbc -a -salt -in $f -out $f.enc -k PASSWORD ; done
- To encrypt all files in one folder with a password that you set in the file author.txt and then remove all the original JPG files and the author.txt file itself for obvious reasons!
- for f in * ; do [ -f $f ] && openssl aes-256-cbc -a -salt -in $f -out $f.enc -pass file:author.txt ; done ; rm *.JPG ; rm *.txt
- To encrypt all files in one folder with a password set in the command line and then erase the bash history and remove all tar files. We remove the bash history so that your password is not retrievable by simply pressing the up arrow key!
- for f in * ; do [ -f $f ] && openssl aes-256-cbc -a -salt -in $f -out $f.enc -k PASSWORD ; done ; rm *.tar ; history -c && history -w
- Encrypt & Decrypt all files recursively from parent directory
- =============================================================
- Encrypt all files recursively with a password set from the command line and then erase the bash history and remove all the original tar files.
- This assumes that the files to be encrypted are tar files, you can of course run the command on any type of file extension.
- for f in **/*.tar ; do [ -f $f ] && openssl aes-256-cbc -a -salt -in $f -out $f.enc -k PASSWORD ; done ; rm **/*.tar ; history -c && history -w
- -------------------------------------------------------------------------------------------------------------------------
- Examples
- Delete the testfile if it is is 15 days old or older:
- forfiles /p "D:\CLI" /s /m *.* /D -15 /C "cmd /c del @path"
- Delete the testfile if it is is 5 days old or older:
- C:\> forfiles /m testfile.txt /c "cmd /c Del testfile.txt " /d -5
- Find all .xlsx files that were last modified 30 days ago or older:
- C:\> FORFILES /M *.xlsx /C "cmd /c echo @path was changed 30 days ago" /D -30
- List the size of all .doc files:
- C:\> FORFILES /S /M *.doc /C "cmd /c echo @fsize"
- Run a command against each text file newer than 1st Jan 2001:
- C:\> FORFILES /D +01/01/2021 /m *.txt /C "CMD /c echo @fname is new since Jan 1st 2021"
- FORFILES /D +01/01/2024 /m *.* /C "cmd /c del @path"
- FORFILES /P "D:\F" /S /D +01/01/2024 /M *.* /C "cmd /c del @path"
- FORFILES /P "D:\F" /S /D -01/01/2024 /M *.* /C "cmd /c del @path"
- ----------------------------------------------------------------------------------------
- 3. Once you are in the correct directory, type the following command to change the creation date and time:
- copy /b filename +, , where "filename" is the name of the file you want to modify.
- 4. To change the modification date and time, use the following command:
- copy /b M.cmd +,,
- copy /b filename.ext +,,
- 5. To change the last access date and time, use the following command:
- copy /b filename +,,
- 6. Replace "filename" with the actual name of the file, and make sure to remove the "," symbols when using the commands.
- 7. Press Enter to execute the command. The file’s dates and times will be modified accordingly.
- ----------------------------------------------------------------------------------------------
- Here are the notes from the Power Shell .
- DATE CREATED
- (Get-Item "PathToItem").CreationTime=("15 January 2022 10:00:00")
- SAMPLE
- (Get-Item "D:\F\N\M.cmd").CreationTime=("15 January 2024 10:00:00")
- -------------------------------------------------------------------------------
- DATE MODIFIED
- (Get-Item "PathToItem").LastWriteTime=("16 January 2022 11:00:00")
- SAMPLE
- (Get-Item "D:\F\N\M.cmd").LastWriteTime=("16 January 2024 11:00:00")
- -------------------------------------------------------------------------------
- DATE ACCESSED
- (Get-Item "PathToItem").LastAccessTime=("17 January 2022 12:00:00")
- SAMPLE
- (Get-Item "C:\demo\File3.txt").LastAccessTime=("17 January 2022 12:00:00")
- -------------------------------------------------------------------------------
- If date accessed is not changing then run
- fsutil behavior set disablelastaccess 0
- -------------------------------------------------------------------------------
- CHANGE ATTRIBUTES FOR ALL FILES IN A FOLDER
- Get-ChildItem -force PathToItem * | ForEach-Object{$_.CreationTime = ("15 January 2022 10:00:00")}
- Get-ChildItem -force PathToItem * | ForEach-Object{$_.LastWriteTime = ("15 January 2022 10:00:00")}
- Get-ChildItem -force PathToItem * | ForEach-Object{$_.LastAccessTime = ("15 January 2022 10:00:00")}
- SAMPLE
- Get-ChildItem -force C:\demo\Folder1 * | ForEach-Object{$_.CreationTime = ("15 January 2022 10:00:00")}
Add Comment
Please, Sign In to add comment