-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
88 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
title: "FIND LINUX BROKEN SYMLINKS" | ||
date: 2023-11-07T20:46:53Z | ||
draft: false | ||
tags: ["Linux", "symlinks"] | ||
categories: ["tips"] | ||
align: left | ||
featuredImage: banner.en.png | ||
--- | ||
|
||
## Find broken symbolic links | ||
|
||
A while ago, I was willing to contribute with a GitHub project, but I found some issues with broken links. This situation led me to a question: how can I recursively find all broken links within a directory? | ||
|
||
The command below will print the path to any broken symbolic links found in the specified folder and its subfolders. | ||
|
||
```shell | ||
find /path/to/folder -type l ! -exec test -e {} \; -print | ||
``` | ||
|
||
Let's explain each part of the command does: | ||
|
||
- `find /path/to/folder`: Search recursively starting from the specified folder. | ||
- `-type l`: Only look for symbolic links. | ||
- `! -exec test -e {} \;`: Use the test command to check if each symbolic link exists. The `{}` is a placeholder for the path to the symbolic link. The `-e` option to test checks if the file exists. The `!` negates the result of the test, so the command will succeed if the file does not exist (i.e., if the symbolic link is broken). | ||
- `-print`: Print the path to any broken symbolic links found. | ||
|
||
## Conclusion | ||
|
||
With the list of broken symbolic links, to fix the issue, it is just a matter of recreating the links pointing to the right locations. |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--- | ||
title: "LINUX, HOW TO FIND FILES BY AGE" | ||
date: 2023-11-07T21:15:56Z | ||
draft: false | ||
tags: ["Linux", "find"] | ||
categories: ["tips"] | ||
align: left | ||
featuredImage: banner.en.png | ||
--- | ||
|
||
## Find files by age | ||
|
||
A while ago I needed to find old files in a Linux server. The `find` utility have the `-mtime` option to complete this task. | ||
|
||
Here's an example command: | ||
|
||
```shell | ||
find /path/to/directory -type f -mtime +730 | ||
``` | ||
|
||
Running this command will list all the files in the specified directory (and its subdirectories) that are older than two years. | ||
|
||
Let's break down the command: | ||
|
||
- `find /path/to/directory`: Search recursively starting from the specified folder. | ||
- `-type f`: This option specifies that we are looking for regular files (excluding directories and other special file types). | ||
- `-mtime +730`: This option specifies the modification time of the files. The +730 means files older than 730 days (365 days x 2 years). | ||
|
||
Note that the modification time of a file is based on the last time it was modified, including changes to its content, permissions, or ownership. | ||
|
||
## Conclusion | ||
|
||
The `find` utility have several options and possibilities, always check the software manual pages with `man find` or [online](https://linux.die.net/man/1/find). |